dotnet / dotnet/aspnetcore

Undocumented breaking change in ASP.NET Core 7 model binding when using Nullability and model contains generic field

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

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

I guess this is more due to the docs not covering it, but there is a breaking change for how ASP.NET Core 7 handles nullability and Required fields for model binding. It's lacking from this list: https://learn.microsoft.com/en-us/dotnet/core/compatibility/7.0

### Expected Behavior

Either the same behaviour re model binding between 6 and 7, or the docs listing this specific detail as a breaking change.

### Steps To Reproduce

https://github.com/johnkors/aspnetcore7-compat-repro

GitHub actions running the tests in both 6 and 7 is provided, which shows _one_ test running OK in ASP.NET Core 6 but failing in 7.

![image](https://user-images.githubusercontent.com/206726/232479912-579de6f3-7186-4896-b888-a563d8141e31.png)

There is a small difference in how nullability and required is handled if the model contains 1 vs more than 1 fields, and the model contains a generic field.

### Exceptions (if any)

_No response_

### .NET Version

7

### Anything else?

ASP.NET Core 7

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.