Skip to content

Revert "Fixed AmbiguousMatchException in DataAnnotationsValidator for Hidden Members (#67075)"#67712

Merged
javiercn merged 1 commit into
mainfrom
copilot/revert-hidden-member-validation-fix
Jul 10, 2026
Merged

Revert "Fixed AmbiguousMatchException in DataAnnotationsValidator for Hidden Members (#67075)"#67712
javiercn merged 1 commit into
mainfrom
copilot/revert-hidden-member-validation-fix

Conversation

Copilot AI commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Revert #67075

Description

#67075's DeclaredOnlyFlattenHierarchy fallback in TryGetValidatableProperty doesn't actually fix the AmbiguousMatchException it targeted — FlattenHierarchy doesn'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 with PropertyHelper.GetVisibleProperties and Microsoft.Extensions.Validation's TryFindProperty.

  • EditContextDataAnnotationsExtensions.cs: reverted TryGetValidatableProperty to the original single GetProperty(cacheKey.FieldName) lookup, restoring the loud AmbiguousMatchException for new-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: avoid new-hiding a validated property (rename or drop new).

Copilot AI changed the title [WIP] Revert #67075: Restore original AmbiguousMatchException behavior Revert "Fixed AmbiguousMatchException in DataAnnotationsValidator for Hidden Members (#67075)" Jul 9, 2026
Copilot AI requested a review from javiercn July 9, 2026 20:26
… Hidden Members (#67075)"

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@javiercn javiercn force-pushed the copilot/revert-hidden-member-validation-fix branch from bdaac56 to b282a94 Compare July 10, 2026 06:39
@javiercn javiercn marked this pull request as ready for review July 10, 2026 08:49
@javiercn javiercn requested a review from a team as a code owner July 10, 2026 08:49
Copilot AI review requested due to automatic review settings July 10, 2026 08:49
@javiercn javiercn enabled auto-merge (squash) July 10, 2026 08:49

Copilot AI 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.

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 TryGetValidatableProperty to a single Type.GetProperty(string) lookup (removing the DeclaredOnly/FlattenHierarchy fallback 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
@javiercn javiercn merged commit 56326e6 into main Jul 10, 2026
26 checks passed
@javiercn javiercn deleted the copilot/revert-hidden-member-validation-fix branch July 10, 2026 16:33
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 13, 2026
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.

Revert #67075: hidden-member validation fix is incomplete and regresses behavior

4 participants