Skip to content

Clarify assembly requirements for AddValidation() in .NET 10 Minimal APIs - #37419

Open
wadepickett with Copilot wants to merge 9 commits into
mainfrom
copilot/clarify-source-generator-requirements
Open

Clarify assembly requirements for AddValidation() in .NET 10 Minimal APIs#37419
wadepickett with Copilot wants to merge 9 commits into
mainfrom
copilot/clarify-source-generator-requirements

Conversation

Copilot AI commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

AddValidation() uses a compile-time source generator that only discovers validatable types in the assembly where it's called. When endpoints live in a referenced assembly but AddValidation() is registered in the host, validation silently doesn't run—invalid payloads return 200 OK instead of 400 Bad Request. The docs didn't call this out.

Changes

  • aspnetcore/fundamentals/minimal-apis.md
    • Added a [!NOTE] on the source-generator/assembly constraint.
    • Added a new Register validation in multi-assembly apps section covering the failing symptom, the extension-method workaround, the multi-assembly case, and troubleshooting.
    • Bumped ms.date.
  • aspnetcore/release-notes/aspnetcore-10/includes/ValidationSupportMinAPI.md — Added a short [!NOTE] cross-referencing the new section.

Workaround documented

Register AddValidation() from within the endpoints' assembly, then call it from the host:

// In the assembly that defines the endpoints
public static class ServiceCollectionExtensions
{
    public static IServiceCollection AddApiValidation(this IServiceCollection services)
        => services.AddValidation();
}

// Host Program.cs
builder.Services.AddApiValidation();

Guidance mirrors the existing Blazor "Use validation models from a different assembly" precedent.


Internal previews

File Preview link
aspnetcore/fundamentals/minimal-apis.md aspnetcore/fundamentals/minimal-apis
aspnetcore/release-notes/aspnetcore-10/includes/ValidationSupportMinAPI.md aspnetcore/release-notes/aspnetcore-10/includes/ValidationSupportMinAPI

Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com>
Copilot AI changed the title [WIP] Clarify source-generator assembly requirements for AddValidation in .NET 10 Clarify assembly requirements for AddValidation() in .NET 10 Minimal APIs Aug 5, 2026
Copilot AI requested a review from wadepickett August 5, 2026 01:12
Comment thread aspnetcore/fundamentals/minimal-apis.md Outdated
Comment thread aspnetcore/fundamentals/minimal-apis.md Outdated
Comment thread aspnetcore/fundamentals/minimal-apis.md Outdated
Co-authored-by: Wade Pickett <wpickett@microsoft.com>
Per reviewer sugestion: Updated namespace references for service collection extensions and usage in the Program file.
Co-authored-by: Wade Pickett <wpickett@microsoft.com>
Comment thread aspnetcore/fundamentals/minimal-apis.md
Co-authored-by: Wade Pickett <wpickett@microsoft.com>
Added section on customizing validation error responses using IProblemDetailsService.
@wadepickett
wadepickett marked this pull request as ready for review August 5, 2026 02:04

@wadepickett wadepickett left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved (after changes were made).

2nd Reviewer approval still required. @gumbarros does this look OK to you? Publish?

@wadepickett
wadepickett requested review from tdykstra and removed request for gumbarros August 5, 2026 03:04
@gumbarros

Copy link
Copy Markdown

Approved (after changes were made).

2nd Reviewer approval still required. @gumbarros does this look OK to you? Publish?

Yes, perfect.

@wadepickett
wadepickett requested a review from gumbarros August 5, 2026 16:10
@wadepickett

Copy link
Copy Markdown
Contributor

Sorry @gumbarros, I accidently sent a review request after you provided one. Please ignore. My I didn't notice my page had not refreshed.

Thanks very much for writing up the issue, your suggestions and providing reviews!!!

@tdykstra tdykstra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Just a couple nits.

Comment thread aspnetcore/fundamentals/minimal-apis.md Outdated
Comment thread aspnetcore/fundamentals/minimal-apis.md Outdated
Co-authored-by: Tom Dykstra <tdykstra@microsoft.com>
Co-authored-by: Tom Dykstra <tdykstra@microsoft.com>
@wadepickett
wadepickett requested a review from tdykstra August 5, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify source-generator/assembly requirements for AddValidation() in .NET 10 Minimal APIs

4 participants