dotnet / dotnet/aspnetcore

HttpRequest.Form throws an undocumented System.InvalidOperationException

Open
#49,096 5 comments 0 reactions 1 assignee Claimed by @benjaminpetit View on GitHub
area-networking bug Docs help wanted net8_docathon
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

After upgrading from ASP.NET Core 3.x to ASP.NET Core 6, we found that `HttpRequest.Form` throws an undocumented `System.InvalidOperationException` with the message "Incorrect Content-Type: image/png".

```
System.InvalidOperationException: Incorrect Content-Type: image/png
at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm()
at Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Form()
```

This seems to only affect image files. Using the same code to read CSV files continues to work.

### Expected Behavior

Form object is returned.

### Steps To Reproduce

_No response_

### Exceptions (if any)

System.InvalidOperationException

### .NET Version

7.0.304

### Anything else?

* https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.httprequest.form
* https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.features.formfeature.readform

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.