-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nullable=Enabled results in required validation errors for parameters or bound properties with default values #18403
Comments
@mountain65 thanks for contacting us. @pranavkm any ideas? |
Updated the code to include de [ApiController] attribute |
@mountain65, I admit, this is surprising behavior. Non-nullable reference types are treated as required. MVC executes binding and validation prior to inferring default values, consequently you end up getting validation errors for properties and parameters which is always meant to be non-null in the body of the action. For now, I'd recommend stating that the type is non-null. Alternatively, you may turn off the behavior that implicitly applies non-nullable = Required, by configuring services.AddControllers(options => options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true); |
I will do that. Thanks. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
I generated a new empty WebApplication, .NET Core 3.1 and added 8.0 and enable to my CSPROJ.
Then I added the following controller code:
When I call this endpoint without a language parameter I get a 400 BadRequest with the followin g ProblemDetail:
When I remove the [ApiController] attribute I get the normal optional parameter behaviour once more, OR when I remove the Nullable=enabled option from the CSPROJ.
The text was updated successfully, but these errors were encountered: