Skip to content

Minimal APIs: IFormFile? parameter still throws 'Unexpected request without body" #64902

@mikernet

Description

@mikernet

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

If I have:

public static async Task SetCurrentUserProfileImageAsync(IFormFile? image, [other params])
{
}

But the client sends the request without a body, it still throws the following even thought the IFormFile is nullable:

Microsoft.AspNetCore.Http.BadHttpRequestException: 'Unexpected request without body, failed to bind parameter "IFormFile image" from the request body as form.'

Expected Behavior

If the IFormFile is optional then it should not throw. In the example above, a null IFormFile means the API calll wants to clear the profile image so a body is not required.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

10

Anything else?

No response

Metadata

Metadata

Labels

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

Type

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions