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

Minimal APIs doesn't support binding to StringValues from query or headers #36726

Closed
davidfowl opened this issue Sep 19, 2021 · 0 comments · Fixed by #39809
Closed

Minimal APIs doesn't support binding to StringValues from query or headers #36726

davidfowl opened this issue Sep 19, 2021 · 0 comments · Fixed by #39809
Assignees
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-web-frameworks feature-minimal-actions Controller-like actions for endpoint routing Priority:2 Work that is important, but not critical for the release triage-focus Add this label to flag the issue for focus at triage
Milestone

Comments

@davidfowl
Copy link
Member

davidfowl commented Sep 19, 2021

Describe the bug

Parameter binding doesn't support StringValues (which is ASP.NET Core's native representation of both query string and header values).

To Reproduce

using Microsoft.Extensions.Primitives;

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.MapGet("/", (StringValues query) => query.ToString());

app.Run();

OR

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.MapGet("/", ([FromQuery] StringValues query) => query.ToString());

app.Run();

Exceptions (if any)

The first fails parameter binding things that StringValues is a body parameter.

Unhandled exception. System.InvalidOperationException: Body was inferred but the method does not allow inferred body parameters.
Below is the list of parameters that we found:

Parameter           | Source
---------------------------------------------------------------------------------
query               | Body (Inferred)

Did you mean to register the "Body (Inferred)" parameter(s) as a Service or apply the [FromService] or [FromBody] attribute?

When adding [FromQuery], it also fails but it's because StringValues doesn't have a TryParse method:

Unhandled exception. System.InvalidOperationException: No public static bool StringValues.TryParse(string, out StringValues) method found for query.

It feels bad that our native representation doesn't work...

@davidfowl davidfowl changed the title We don Minimal APIs doesn't support binding to StringValues from query or headers Sep 19, 2021
@davidfowl davidfowl added the feature-minimal-actions Controller-like actions for endpoint routing label Sep 19, 2021
@davidfowl davidfowl added this to Ready in Minimal APIs 6.0 via automation Sep 19, 2021
@rafikiassumani-msft rafikiassumani-msft moved this from Ready to Need review in Minimal APIs 6.0 Sep 20, 2021
@rafikiassumani-msft rafikiassumani-msft removed this from Need review in Minimal APIs 6.0 Sep 20, 2021
@rafikiassumani-msft rafikiassumani-msft added this to the .NET 7 Planning milestone Sep 20, 2021
@rafikiassumani-msft rafikiassumani-msft added triage-focus Add this label to flag the issue for focus at triage Priority:2 Work that is important, but not critical for the release Cost:S labels Jan 11, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Mar 18, 2022
@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-web-frameworks feature-minimal-actions Controller-like actions for endpoint routing Priority:2 Work that is important, but not critical for the release triage-focus Add this label to flag the issue for focus at triage
Projects
None yet
4 participants