Skip to content

Commit a636422

Browse files
author
Bart Koelman
committed
Include resource name in error message
1 parent ff70656 commit a636422

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/JsonApiDotNetCore/Internal/IResourceFactory.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq.Expressions;
44
using System.Reflection;
55
using JsonApiDotNetCore.Extensions;
6-
using JsonApiDotNetCore.Models;
76
using Microsoft.Extensions.DependencyInjection;
87

98
namespace JsonApiDotNetCore.Internal
@@ -70,9 +69,19 @@ public NewExpression CreateNewExpression(Type resourceType)
7069
var longestConstructor = resourceType.GetLongestConstructor();
7170
foreach (ParameterInfo constructorParameter in longestConstructor.GetParameters())
7271
{
73-
var constructorArgument =
74-
ActivatorUtilities.CreateInstance(_serviceProvider, constructorParameter.ParameterType);
75-
constructorArguments.Add(Expression.Constant(constructorArgument));
72+
try
73+
{
74+
object constructorArgument =
75+
ActivatorUtilities.CreateInstance(_serviceProvider, constructorParameter.ParameterType);
76+
77+
constructorArguments.Add(Expression.Constant(constructorArgument));
78+
}
79+
catch (Exception exception)
80+
{
81+
throw new InvalidOperationException(
82+
$"Failed to create an instance of '{resourceType.FullName}': Parameter '{constructorParameter.Name}' could not be resolved.",
83+
exception);
84+
}
7685
}
7786

7887
return Expression.New(longestConstructor, constructorArguments);

0 commit comments

Comments
 (0)