Repository navigation
[release/11.0-preview7]: Move the abstract Validatable*Info from Microsoft.Extensions.Validation to be source-generated - #67975
Merged
wtgodbe merged 1 commit intoJul 23, 2026
Conversation
…tion to be source-generated (#67956) * Refactor validation * Step 2 * Refactor * Move to SG * Introduce * Rename * Snapshots, rename * Generated * Namespace * Reduce comments * Avoid usings. Use global:: * Stable * Remove unused usings * Update failing snapshot tests to remove BOM and pragma Co-authored-by: Youssef1313 <[email protected]> * Initial plan: fix ValidationEndpointFilterFactory test failures Co-authored-by: Youssef1313 <[email protected]> * Fix ValidationEndpointFilterFactory test failures by restoring runtime resolver in AddValidation Co-authored-by: Youssef1313 <[email protected]> * Revert "Fix ValidationEndpointFilterFactory test failures by restoring runtime resolver in AddValidation" This reverts commit 1a52a50. Users are expected to have the source generator available; restoring the source generator reference to the test project instead. Co-authored-by: Youssef1313 <[email protected]> * Simplify ValidationError to a single ErrorMessage and make it a class Address API feedback on #67960: ValidationError carried a plural Errors list that the generator always populated with a single message, while AddValidationError already groups errors by Path. Collapse the redundant axis to a scalar string ErrorMessage and rely on the per-path list. Also make ValidationError a sealed class instead of a readonly struct so default(ValidationError) no longer bypasses the required members and hands back null Name/Path/ErrorMessage. It is only materialized on validation failure, so the extra allocation is not a concern. Update the generator templates, the Blazor EditContext integration, the minimal API endpoint filter, and all affected tests and snapshots. Co-authored-by: Copilot <[email protected]> Copilot-Session: 762782cd-5621-4641-8bea-ecc5675c0dbf * Pass the validated instance to IValidatableObject and drop NotNullWhen from generated resolvers Address PR review feedback and fix the Http.Extensions.Tests CI build break. - ValidationContext for type-level validation now uses `value ?? _throwawayObjectInstance` instead of always passing the throwaway placeholder, so IValidatableObject.Validate (sync and async) receives the model being validated as ObjectInstance. Previously user code that cast ObjectInstance back to the model threw. Adds a regression test covering both paths. - The generated file-local resolver/type-info implementations no longer emit [NotNullWhen] on their out parameters. The public interfaces (IValidatableInfoResolver, IValidatableTypeInfo) keep the attribute, so callers are unaffected, but the emitted code no longer references System.Diagnostics.CodeAnalysis.NotNullWhenAttribute. That reference was ambiguous (CS0433) in compilations where another source generator (e.g. the RequestDelegateGenerator) contributes an internal polyfill of the same attribute via InternalsVisibleTo, which broke the build of Microsoft.AspNetCore.Http.Extensions.Tests. CS8767 on the implementations is suppressed in the generated file. Co-authored-by: Copilot <[email protected]> Copilot-Session: 762782cd-5621-4641-8bea-ecc5675c0dbf --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Ondrej Roztocil <[email protected]> Co-authored-by: Copilot <[email protected]> Copilot-Session: 762782cd-5621-4641-8bea-ecc5675c0dbf
Validatable*Info from Microsoft.Extensions.Validation to be source-generated
Youssef1313
marked this pull request as ready for review
July 23, 2026 11:03
Youssef1313
requested review from
a team,
BrennanConroy and
halter73
as code owners
July 23, 2026 11:03
wtgodbe
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport PR #67956 to release/11.0-preview7
Backport the validation refactor from main so
release/11.0-preview7carries the same source-generatedValidatable*Infomodel and related API shape.Description
Validation model
ValidatableTypeInfo,ValidatablePropertyInfo, andValidatableParameterInfoimplementations out of the shared runtime assembly and into generated code/templates.Validation API updates
ValidationError.ErrorMessageper entry and keep path-based grouping at the call site.IValidatableObjectreceives the validated instance asValidationContext.ObjectInstance.Generator and integration updates
[NotNullWhen]on generated implementations to avoid attribute collisions in consumer compilations.Release branch alignment
Customer Impact
Keeps the preview7 branch aligned with the validation stack already merged to main, including the generated-type model and the corrected
IValidatableObjectbehavior. This avoids divergence in API shape, generated output, and consuming test assets across branches.Regression?
[If yes, specify the version the behavior has regressed from]
Risk
Broad refactor touching generated code, runtime validation flow, and multiple dependent test/assets projects; low conceptual risk, but wide surface area.
Verification
Packaging changes reviewed?
When servicing release/2.3