Skip to content

Nullable=Enabled results in required validation errors for parameters or bound properties with default values #18403

@mountain65

Description

@mountain65

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:

    [ApiController]
    [Route("api/[controller]")]
    public class CountriesController : ControllerBase
    {
        // GET: api/<controller>
        [HttpGet]
        public IEnumerable<string> GetByLanguage(string language="nl")
        {
            Console.WriteLine(language);
            return new[] { "Nederland", "Duitsland", "Amerika"};
        }
    }

When I call this endpoint without a language parameter I get a 400 BadRequest with the followin g ProblemDetail:

    type: "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    title: "One or more validation errors occurred.",
    status: 400,
    traceId: "|a897675b-4df1a9d8146c8919.",
    errors: {
        language: [
            "The language field is required."
        ]
    }
}

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.

Metadata

Metadata

Assignees

Labels

affected-fewThis issue impacts only small number of customersbugThis issue describes a behavior which is not expected - a bug.cost: SWill take up to 2 days to completeenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-model-bindingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labelsseverity-minorThis label is used by an internal tool

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions