Skip to content

Minimal Actions - array support in method signatures from querystring binding #32516

Closed
@jchannon

Description

@jchannon

Describe the bug

When using the ASPP.NET 6 minimal hosting, querystring binding does not work with arrays/lists

To Reproduce

app.MapGet("/qs/{id:int}", HttpHandlers.GetByQueryString);

public static string GetByQueryString(int id, string name, int[] values)
{
    return id + " " + name + string.Join(",", values);
}

Adding [FromQuery(Name = "values")] to the method signature does not help either.

Exceptions (if any)

An exception is thrown when sending in a request:

curl http://localhost:5000/qs/123\?name\=dave\&values\=1\&values\=2

Unhandled exception. System.InvalidOperationException: No public static bool Int32[].TryParse(string, out Int32[]) method found for values.

Further technical details

  • ASP.NET Core version 6
.NET SDK (reflecting any global.json):
 Version:   6.0.100-preview.5.21252.2
 Commit:    921395c33e

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.3
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /Users/jonathan/.dotnet/sdk/6.0.100-preview.5.21252.2/

Host (useful for support):
  Version: 6.0.0-preview.5.21251.4
  Commit:  d2fba8fdc4

.NET SDKs installed:
  2.1.809 [/Users/jonathan/.dotnet/sdk]
  3.1.401 [/Users/jonathan/.dotnet/sdk]
  3.1.403 [/Users/jonathan/.dotnet/sdk]
  5.0.103 [/Users/jonathan/.dotnet/sdk]
  6.0.100-preview.5.21229.26 [/Users/jonathan/.dotnet/sdk]
  6.0.100-preview.5.21252.2 [/Users/jonathan/.dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.21 [/Users/jonathan/.dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.21 [/Users/jonathan/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.7 [/Users/jonathan/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.9 [/Users/jonathan/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.3 [/Users/jonathan/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.5.21229.9 [/Users/jonathan/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.5.21230.5 [/Users/jonathan/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.21 [/Users/jonathan/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.7 [/Users/jonathan/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.9 [/Users/jonathan/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.3 [/Users/jonathan/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-preview.5.21229.1 [/Users/jonathan/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-preview.5.21251.4 [/Users/jonathan/.dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Activity

changed the title [-]Minimal Hosting - array support in method signatures[/-] [+]Minimal Hosting - array support in method signatures from querystring binding[/+] on May 8, 2021
davidfowl

davidfowl commented on May 8, 2021

@davidfowl
Member

Would this only be for simple types? Today we don't support any complex types for model binding and it conflicts with this idea

jchannon

jchannon commented on May 8, 2021

@jchannon
ContributorAuthor

Yup simple types only imo, it's a query string, you shouldn't be doing crazy stuff like json binding. I mean there's nothing stopping someone adding json in a querystring I just don't think the framework should support that

changed the title [-]Minimal Hosting - array support in method signatures from querystring binding[/-] [+]Minimal Actions - array support in method signatures from querystring binding[/+] on May 10, 2021
added this to the Backlog milestone on May 10, 2021
ghost

ghost commented on May 10, 2021

@ghost

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

added
enhancementThis issue represents an ask for new feature or an enhancement to an existing one
on May 10, 2021
halter73

halter73 commented on Jul 8, 2021

@halter73
Member

What collection types should we support?

What should we do if we know the param comes from the route? Fail at startup? Provide a single-element array?

DamianEdwards

DamianEdwards commented on Aug 23, 2021

@DamianEdwards
Member

With the newly added support for BindAsync(HttpContext) on the target parameter type it would be easy to support this in the app or a library via a custom type, e.g. MultiValueQuery values, where MultiValueQuery has a BindAsync method on it.

15 remaining items

davidfowl

davidfowl commented on Feb 3, 2022

@davidfowl
Member

@jchannon This is supported in .NET 7 preview1

davidfowl

davidfowl commented on Feb 4, 2022

@davidfowl
Member

I mean preview2

added
DocsThis issue tracks updating documentation
and removed
triage-focusAdd this label to flag the issue for focus at triage
on Feb 10, 2022
legistek

legistek commented on Feb 23, 2022

@legistek

Previously (in Framework) you could serialize an array of primitives to a JSON object in the query string like this:

?values=[1,2,3,4,5]

(escaped obviously)

and the method:

DoSomething(int[] values)

would bind correctly. That doesn't appear to be the case in .NET6 (or possibly earlier). I assume that was a known breaking change but I thought it worth asking? If it was not an intentional change then it's a different bug I guess.

davidfowl

davidfowl commented on Feb 23, 2022

@davidfowl
Member

This issue isn't about MVC's binding semantics and minimal API supports a subset of what MVC supports. If you want to see what is supported for MVC today look at https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-6.0#collections

legistek

legistek commented on Feb 23, 2022

@legistek

Thanks. Sorry this seemed like the closest issue to what I'm experiencing that wasn't locked by the bots.

davidfowl

davidfowl commented on Feb 23, 2022

@davidfowl
Member

Thanks. Sorry this seemed like the closest issue to what I'm experiencing that wasn't locked by the bots.

😄. FWIW, it's not supported in MVC either, that's by design.

ghost locked as resolved and limited conversation to collaborators on Mar 25, 2022
added
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
on Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

DocsThis issue tracks updating documentationPriority:2Work that is important, but not critical for the releasearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-minimal-actionsController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Relationships

None yet

    Participants

    @halter73@davidfowl@jchannon@DamianEdwards@Pilchie

    Issue actions

      Minimal Actions - array support in method signatures from querystring binding · Issue #32516 · dotnet/aspnetcore