Revert "Fixed AmbiguousMatchException in DataAnnotationsValidator for Hidden Members (#67075)"#67712
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Revert #67075: Restore original AmbiguousMatchException behavior
Revert "Fixed AmbiguousMatchException in DataAnnotationsValidator for Hidden Members (#67075)"
Jul 9, 2026
Youssef1313
approved these changes
Jul 9, 2026
… Hidden Members (#67075)" Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
bdaac56 to
b282a94
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Reverts PR #67075 by removing the hidden-member property-resolution fallback in Blazor’s EditContext DataAnnotations validation path, restoring the previous behavior where new-hidden properties can result in an AmbiguousMatchException.
Changes:
- Reverted
TryGetValidatablePropertyto a singleType.GetProperty(string)lookup (removing theDeclaredOnly/FlattenHierarchyfallback logic). - Removed the unit tests and model types that validated the hidden-member fallback behavior introduced by #67075.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Components/Forms/src/EditContextDataAnnotationsExtensions.cs | Reverts the reflection-based property lookup used for field-level validation. |
| src/Components/Forms/test/EditContextDataAnnotationsExtensionsTest.cs | Removes tests/models added for the reverted hidden-member behavior. |
Comment on lines
367
to
372
| { | ||
| // DataAnnotations only validates public properties, so that's all we'll look for | ||
| // If we can't find it, cache 'null' so we don't have to try again next time | ||
| propertyInfo = cacheKey.ModelType.GetProperty( | ||
| cacheKey.FieldName, | ||
| BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); | ||
|
|
||
| if (propertyInfo is null) | ||
| { | ||
| propertyInfo = cacheKey.ModelType.GetProperty( | ||
| cacheKey.FieldName, | ||
| BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy); | ||
| } | ||
| propertyInfo = cacheKey.ModelType.GetProperty(cacheKey.FieldName); | ||
|
|
||
| // No need to lock, because it doesn't matter if we write the same value twice |
Youssef1313
approved these changes
Jul 10, 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.
Revert #67075
Description
#67075's
DeclaredOnly→FlattenHierarchyfallback inTryGetValidatablePropertydoesn't actually fix theAmbiguousMatchExceptionit targeted —FlattenHierarchydoesn't flatten instance members, so hiding at an intermediate base type still throws. It also silently drops validation attributes depending on which hierarchy level resolves, with no diagnostic, and adds a third property-resolution policy inconsistent withPropertyHelper.GetVisiblePropertiesandMicrosoft.Extensions.Validation'sTryFindProperty.EditContextDataAnnotationsExtensions.cs: revertedTryGetValidatablePropertyto the original singleGetProperty(cacheKey.FieldName)lookup, restoring the loudAmbiguousMatchExceptionfornew-hidden properties.EditContextDataAnnotationsExtensionsTest.cs: removed the tests and model classes added by Fixed AmbiguousMatchException in DataAnnotationsValidator for Hidden Members #67075, including the one that enshrined the silent attribute-dropping behavior as expected.The unsupported
new-hiding scenario is intentionally left as a loud exception rather than a new silent-resolution policy. Workaround remains: avoidnew-hiding a validated property (rename or dropnew).