Skip to content

Should a required array bound to query string throw an exception when omitted? #44102

Description

@mauler2025

I am not sure whether the current implementation is a bug or a feature.

If we navigate to "/" without specifying the required x, the framework does not throw an exception.
Interestingly x is set to a zero-length array.

app.MapGet("/", ([FromQuery] int[] x) =>
{
    return $"Length of x is : {x.Length}";
});

But if I change the binding source from FromQuery to FromBody, the framework behaves as expected.
It does throw an exception if the required x is omitted.

Question:

Should a required array bound to query string throw an exception when omitted?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions