[release/10.0] Emit validation info for types that have IValidatableObject interface and no validation attributes #63415
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 of #63414 to release/10.0
/cc @javiercn @oroztocil
Emit validation info for types that have IValidatableObject interface and no validation attributes
Fixes issue with a supported scenario in the new validation infrastructure used by Minimal APIs and Blazor.
Description
Currently, when you use the new validation features (enabled by the
AddValidationcall during application startup) and have a type that is validated only with theIValidatbleObjectmethod (i.e. the type has no validation attributes or properties with validation attributes), then theMicrosoft.Extensions.Validationsource generator does not create the necessary code for that type. This leads to the validation rule being ignored during run-time.This PR changes the logic in
ValidationsGenerator.ExtractValidatableTypesso that such types get their validation code properly emitted.Fixes #63394
Customer Impact
This bug prevents validations from working in a legitimate scenario which we claim as supported.
Regression?
This fixes a bug in a new feature released in .NET 10.
Risk
This fixes a bug in a special scenario for a new feature released in .NET 10.
Verification
Manual testing: Verified that a Minimal API app that reproduced the reported problem now works as expected.
Automated tests: Added new test coverage for the impacted scenarios.
Packaging changes reviewed?