The Wayback Machine - https://web.archive.org/web/20210918164849/https://github.com/dotnet/aspnetcore/issues/36649
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support binding parameters to type Uri in Minimal Actions #36649

Open
martincostello opened this issue Sep 17, 2021 · 2 comments
Open

Support binding parameters to type Uri in Minimal Actions #36649

martincostello opened this issue Sep 17, 2021 · 2 comments

Comments

@martincostello
Copy link
Contributor

@martincostello martincostello commented Sep 17, 2021

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:

  1. Minimal Actions (RequestDelegateFactory) special-cases Uri to bind parameters;
  2. Minimal Actions supports extending model binding for types not owned by the application where a TryParse or BindAsync method cannot be added;
  3. The Uri type adds a TryParse() 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.

@davidfowl
Copy link
Contributor

@davidfowl davidfowl commented Sep 17, 2021

Yes this is because MVC supports TypeConverters natively. We could choose to do this as well but there are some concerns around that subsystem and AOT friendliness. If we did this, we would support Uri natively or support it via TypeConverter.

@davidfowl davidfowl added this to Ready in Minimal APIs 6.0 via automation Sep 17, 2021
@rafikiassumani-msft rafikiassumani-msft moved this from Ready to Need review in Minimal APIs 6.0 Sep 17, 2021
@rafikiassumani-msft rafikiassumani-msft removed this from Need review in Minimal APIs 6.0 Sep 17, 2021
@rafikiassumani-msft rafikiassumani-msft added this to the .NET 7 Planning milestone Sep 17, 2021
@rafikiassumani-msft
Copy link
Contributor

@rafikiassumani-msft rafikiassumani-msft commented Sep 17, 2021

We will revisit this in NET7. We might examine the following suggestion: The Uri type adds a TryParse() method that can be consumed by the built-in binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants