@@ -56,6 +56,7 @@ public static partial class RequestDelegateFactory
56
56
private static readonly MethodInfo ValueTaskOfTToValueTaskOfObjectMethod = typeof ( RequestDelegateFactory ) . GetMethod ( nameof ( ValueTaskOfTToValueTaskOfObject ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
57
57
private static readonly MethodInfo PopulateMetadataForParameterMethod = typeof ( RequestDelegateFactory ) . GetMethod ( nameof ( PopulateMetadataForParameter ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
58
58
private static readonly MethodInfo PopulateMetadataForEndpointMethod = typeof ( RequestDelegateFactory ) . GetMethod ( nameof ( PopulateMetadataForEndpoint ) , BindingFlags . NonPublic | BindingFlags . Static ) ! ;
59
+ private static readonly MethodInfo ArrayEmptyMethod = typeof ( Array ) . GetMethod ( nameof ( Array . Empty ) , BindingFlags . Public | BindingFlags . Static ) ! ;
59
60
60
61
// Call WriteAsJsonAsync<object?>() to serialize the runtime return type rather than the declared return type.
61
62
// https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-polymorphism
@@ -388,9 +389,12 @@ private static Expression CreateRouteHandlerInvocationContextBase(FactoryContext
388
389
// In the event that a constructor matching the arity of the
389
390
// provided parameters is not found, we fall back to using the
390
391
// non-generic implementation of RouteHandlerInvocationContext.
392
+ Expression paramArray = factoryContext . BoxedArgs . Length > 0
393
+ ? Expression . NewArrayInit ( typeof ( object ) , factoryContext . BoxedArgs )
394
+ : Expression . Call ( ArrayEmptyMethod . MakeGenericMethod ( new Type [ ] { typeof ( object ) } ) ) ;
391
395
var fallbackConstruction = Expression . New (
392
396
DefaultRouteHandlerInvocationContextConstructor ,
393
- new Expression [ ] { HttpContextExpr , Expression . NewArrayInit ( typeof ( object ) , factoryContext . BoxedArgs ) } ) ;
397
+ new Expression [ ] { HttpContextExpr , paramArray } ) ;
394
398
395
399
var arguments = new Expression [ factoryContext . ArgumentExpressions . Length + 1 ] ;
396
400
arguments [ 0 ] = HttpContextExpr ;
0 commit comments