Skip to content

Minimal API : Converting empty string to Nullable (ex: bool?) with [FromQuery] binding #65754

Description

@saithis

Is there an existing issue for this?

  • 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: #55202 but either it is wrongly closed or it was just fixed for [FromForm].

The linked PR introduced this check:

return Type.GetTypeCode(type) != TypeCode.Object || IsSupportedUnderlyingObjectType(type);

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

Metadata

Metadata

Assignees

Labels

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

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions