-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Any non-nullable non-primitive value type parameter in endpoint declaration can not be optional.
Expected Behavior
Parameter must be just optional and have default value if not specified.
Steps To Reproduce
Map endpoint like that:
app.MapGet("/test", ([FromQuery] Guid optionalGuid = default) => { });Exceptions (if any)
System.ArgumentException: "Argument types do not match":
System.Linq.Expressions.Expression.Constant(object, System.Type)
Microsoft.AspNetCore.Http.RequestDelegateFactory.BindParameterFromValue(System.Reflection.ParameterInfo, System.Linq.Expressions.Expression, Microsoft.AspNetCore.Http.RequestDelegateFactoryContext, string)
Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArgument(System.Reflection.ParameterInfo, Microsoft.AspNetCore.Http.RequestDelegateFactoryContext)
Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArguments(System.Reflection.ParameterInfo[], Microsoft.AspNetCore.Http.RequestDelegateFactoryContext)
Microsoft.AspNetCore.Http.RequestDelegateFactory.CreateArgumentsAndInferMetadata(System.Reflection.MethodInfo, Microsoft.AspNetCore.Http.RequestDelegateFactoryContext)
Microsoft.AspNetCore.Http.RequestDelegateFactory.InferMetadata(System.Reflection.MethodInfo, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions)
Microsoft.AspNetCore.Routing.RouteEndpointDataSource.CreateRouteEndpointBuilder(Microsoft.AspNetCore.Routing.RouteEndpointDataSource.RouteEntry, Microsoft.AspNetCore.Routing.Patterns.RoutePattern, System.Collections.Generic.IReadOnlyList<System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder>>, System.Collections.Generic.IReadOnlyList<System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder>>)
Microsoft.AspNetCore.Routing.RouteEndpointDataSource.Endpoints.get()
Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.CreateEndpointsUnsynchronized()
Microsoft.AspNetCore.Routing.CompositeEndpointDataSource.EnsureEndpointsInitialized()
...
.NET Version
8.0.22
Anything else?
No response
Metadata
Metadata
Assignees
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc