File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
src/JsonApiDotNetCore/Internal Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 3
3
using System . Linq . Expressions ;
4
4
using System . Reflection ;
5
5
using JsonApiDotNetCore . Extensions ;
6
- using JsonApiDotNetCore . Models ;
7
6
using Microsoft . Extensions . DependencyInjection ;
8
7
9
8
namespace JsonApiDotNetCore . Internal
@@ -70,9 +69,19 @@ public NewExpression CreateNewExpression(Type resourceType)
70
69
var longestConstructor = resourceType . GetLongestConstructor ( ) ;
71
70
foreach ( ParameterInfo constructorParameter in longestConstructor . GetParameters ( ) )
72
71
{
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
+ }
76
85
}
77
86
78
87
return Expression . New ( longestConstructor , constructorArguments ) ;
You can’t perform that action at this time.
0 commit comments