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?
I am not sure whether the current implementation is a bug or a feature.
If we navigate to
"/"without specifying the requiredx, the framework does not throw an exception.Interestingly
xis set to a zero-length array.But if I change the binding source from
FromQuerytoFromBody, the framework behaves as expected.It does throw an exception if the required
xis omitted.Question:
Should a required array bound to query string throw an exception when omitted?