Minimal API : Converting empty string to Nullable (ex: bool?) with [FromQuery] binding
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
With a Minimal API endpoint like this:
`app.MapGet("foobar", ([FromQuery] bool? myBool) => Results.Ok());`
When I call it like this:
`https://my.domain/foobar?myBool=`
I get a 500 internal server error.
With controllers this worked just fine and `myBool` was `null`.
I saw a somewhat similar issue, that is already closed: https://github.com/dotnet/aspnetcore/issues/55202 but either it is wrongly closed or it was just fixed for `[FromForm]`.
The linked PR introduced this check: https://github.com/dotnet/aspnetcore/blob/1fd3d6a1b857aa774ec957c41909600f05c89624/src/Components/Endpoints/src/FormMapping/Converters/NullableConverter.cs#L61
But `Type.GetTypeCode(typeof(bool?)` returns `Object`, so this code shouldn't even work for `[FromForm]` with `bool?`, `int?`, etc.
### Expected Behavior
I would have expected that `?myBool=` would result in null if `myBool` is nullable.
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
10.0.103
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.