Closed
Description
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...
Metadata
Metadata
Assignees
Labels
Work that is important, but not critical for the releaseIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcController-like actions for endpoint routing*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