dotnet / dotnet/aspnetcore

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

Open
#44,102 3 comments 0 reactions 0 assignees View on GitHub
area-minimal
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

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.

```csharp
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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.