Closed
Description
Is your feature request related to a problem? Please describe.
In MVC controllers actions, it is possible to strongly-type a parameter expected to be a URI as Uri
. For example:
public IActionResult MyAction([FromQuery(Name = "redirect_uri")] Uri? redirectUri)
{
// Implementation
}
However, attempting to replicate this with a Minimal Action endpoint results in an exception being thrown.
app.MapGet("/my-action", ([FromQuery(Name = "redirect_uri")] Uri? redirectUri) =>
{
// Implementation
});
Message:
System.InvalidOperationException : No public static bool Uri.TryParse(string, out Uri) method found for redirectUri.
Stack Trace:
RequestDelegateFactory.BindParameterFromValue(ParameterInfo parameter, Expression valueExpression, FactoryContext factoryContext)
RequestDelegateFactory.CreateArgument(ParameterInfo parameter, FactoryContext factoryContext)
RequestDelegateFactory.CreateArguments(ParameterInfo[] parameters, FactoryContext factoryContext)
RequestDelegateFactory.CreateTargetableRequestDelegate(MethodInfo methodInfo, RequestDelegateFactoryOptions options, FactoryContext factoryContext, Expression targetExpression)
RequestDelegateFactory.Create(Delegate handler, RequestDelegateFactoryOptions options)
DelegateEndpointRouteBuilderExtensions.Map(IEndpointRouteBuilder endpoints, RoutePattern pattern, Delegate handler)
DelegateEndpointRouteBuilderExtensions.MapMethods(IEndpointRouteBuilder endpoints, String pattern, IEnumerable`1 httpMethods, Delegate handler)
DelegateEndpointRouteBuilderExtensions.MapGet(IEndpointRouteBuilder endpoints, String pattern, Delegate handler)
Describe the solution you'd like
Either of:
- Minimal Actions (
RequestDelegateFactory
) special-casesUri
to bind parameters; - Minimal Actions supports extending model binding for types not owned by the application where a
TryParse
orBindAsync
method cannot be added; - The
Uri
type adds aTryParse()
method that can be consumed by the built-in binding.
Additional context
Found using .NET SDK 6.0.100-rc.1.21458.32
to port an existing MVC application to use Minimal Actions.
Metadata
Metadata
Assignees
Labels
Work that is nice to haveIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcController-like actions for endpoint routingUp for grabs. We would accept a PR to help resolve this issue*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labelsAdd this label to flag the issue for focus at triage