Skip to content

Using AddValidation causes non-validated Minimal API endpoints to continue after parsing errors #64341

@aelij

Description

@aelij

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

After adding validation to ASP.NET Core, Minimal API endpoints that used to return 400 on parsing errors, now return 400 and continue execution of the endpoint handler.

IMO this is a symptom of a more generic issue - when using AddEndpointFilterFactory and returning the next delegate as-is, the same problem occurs.

Expected Behavior

Return 400 and stop.

Steps To Reproduce

AddValidation issue:

builder.Services.AddValidation();
...
app.MapGet("/x/{id}", (Guid id) => 1);

AddEndpointFilterFactory issue:

app.MapGet("/x/{id}", (Guid id) => 1).AddEndpointFilterFactory((_, next) => next);

Both produce 400 + the response body 1 when the GUID is invalid.

Exceptions (if any)

No response

.NET Version

10.0.100

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-validationIssues related to model validation in minimal and controller-based APIs

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions