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 33using System . Linq . Expressions ;
44using System . Reflection ;
55using JsonApiDotNetCore . Extensions ;
6- using JsonApiDotNetCore . Models ;
76using Microsoft . Extensions . DependencyInjection ;
87
98namespace 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 ) ;
You can’t perform that action at this time.
0 commit comments