Fixed AmbiguousMatchException in DataAnnotationsValidator for Hidden Members#67075
Merged
Conversation
Contributor
|
Thanks for your PR, @PreethikaSelvam. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
5882542 to
7a1e179
Compare
Open
3 tasks
7a1e179 to
a0d611f
Compare
3 tasks
2e22ee0 to
9c17dd8
Compare
2c8f467 to
895ec8f
Compare
ilonatommy
reviewed
Jul 7, 2026
ilonatommy
reviewed
Jul 7, 2026
ilonatommy
reviewed
Jul 7, 2026
eb17e44 to
3aa499a
Compare
ilonatommy
approved these changes
Jul 7, 2026
Member
|
The CI is always running on PR branch merged to main. In case there would be unresolved conflicts, there would be an information about it on the PR. Merging with main when there are no conflicts and when you're not aware of any recent changes that could influence your feature prolongs the time-to-merge of the PR. |
auto-merge was automatically disabled
July 8, 2026 05:08
Head branch was pushed to by a user without write access
ilonatommy
approved these changes
Jul 8, 2026
Member
|
/ba-g failures not connected |
Youssef1313
reviewed
Jul 9, 2026
| { | ||
| propertyInfo = cacheKey.ModelType.GetProperty( | ||
| cacheKey.FieldName, | ||
| BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy); |
Member
There was a problem hiding this comment.
FlattenHierarchy is only relevant for statics IIRC.
And this code can still throw if the previous call returned null and we get into here with some shadowing member in a base type.
4 tasks
Copilot AI
added a commit
that referenced
this pull request
Jul 9, 2026
… Hidden Members (#67075)" Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
javiercn
added a commit
that referenced
this pull request
Jul 10, 2026
… Hidden Members (#67075)" Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
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.
Bug Description
This PR fixes an issue where the Blazor DataAnnotationsValidator throws an AmbiguousMatchException when validating models that contain hidden properties (i.e., derived class properties declared using new to hide base class members).
Fixes #27095
Problem
When a model includes properties with the same name in both base and derived classes, validation fails with:
System.Reflection.AmbiguousMatchException. This breaks form validation scenarios in Blazor when inheritance with member hiding is used.Root Cause
The issue originates from the use of:
Type.GetProperty(string name). This reflection call returns multiple matches when both base and derived types define a property with the same name, resulting in ambiguity and an exception.Solution Description
Added handling for AmbiguousMatchException. On exception, retried property resolution using:
BindingFlags.DeclaredOnly. This ensures that only properties declared on the current (derived) type are considered, avoiding ambiguityOutput Screenshots
Before Fix
GH27095BeforeFix.1.mp4
After Fix
GH27095AfterFix.mp4
Testing
Added 3 new unit test cases covering:
Impact
PR Checklist