Skip to content

[release/10.0] Skip indexer properties in validation source generator - #65458

Merged
wtgodbe merged 3 commits into
release/10.0from
backport/pr-65432-to-release/10.0
May 27, 2026
Merged

[release/10.0] Skip indexer properties in validation source generator#65458
wtgodbe merged 3 commits into
release/10.0from
backport/pr-65432-to-release/10.0

Conversation

@github-actions

@github-actions github-actions Bot commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

Backport of #65432 to release/10.0

/cc @adityamandaleeka

Skip indexer properties in validation source generator

Fix validation source generator crash on types with indexers

Description

The validation source generator crashes at runtime when encountering types with indexers (e.g. JsonElement, Dictionary<,>) used as minimal API endpoint parameters with AddValidation() enabled. The generator emits indexer properties (this[]) as ValidatablePropertyInfo entries, but at runtime DeclaringType.GetProperty("this[]") returns null because reflection names indexers "Item", causing:

System.InvalidOperationException: Property 'this[]' not found on type 'JsonElement'.

The fix adds member.IsIndexer (plus defensive checks for static, write-only, and non-public-getter properties) to the existing skip filter in ExtractValidatableMembers. These are not meaningful targets for data annotation validation.

Fixes #65424

Customer Impact

Customer reported. Using JsonElement, JsonDocument, or Dictionary<,> as minimal API parameters with AddValidation() causes an unhandled InvalidOperationException at runtime. No workaround exists other than avoiding these common types or disabling validation entirely.

In addition, there are other cases that involve circularity with static properties. This was reported later in #66691

Regression?

  • Yes
  • No

Not a regression from a previous release — the validation feature is new in 10.0. This is a bug-at-birth in the shipped feature.

Risk

  • High
  • Medium
  • Low

7 lines changed in 1 source file. The fix adds additional skip conditions to an existing property filter. Skipped members (indexers, static, write-only, non-public getter) were never valid validation targets and previously caused runtime crashes. ~145 test lines added with a 20:1 test-to-src ratio.

This also has shipped in .NET 11 previews with no reported regressions.

Verification

  • Manual (required)
  • Automated

All 27 generator tests pass, including 2 new tests: SkipsIndexerPropertiesOnTypes and SkipsNonReadableAndStaticProperties.

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@github-actions github-actions Bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Feb 18, 2026
@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 25, 2026
@Youssef1313 Youssef1313 added this to the 10.0.x milestone May 27, 2026
@Youssef1313 Youssef1313 added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-validation Issues related to model validation in minimal and controller-based APIs and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels May 27, 2026
@tkapin tkapin added the Servicing-consider Shiproom approval is required for the issue label May 27, 2026
@Youssef1313 Youssef1313 added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels May 27, 2026
@Youssef1313

Copy link
Copy Markdown
Member

Approved via email.

@rbhanda rbhanda modified the milestones: 10.0.x, 10.0.10 May 27, 2026
@Youssef1313 Youssef1313 removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label May 27, 2026
@wtgodbe
wtgodbe merged commit f70111b into release/10.0 May 27, 2026
28 checks passed
@wtgodbe
wtgodbe deleted the backport/pr-65432-to-release/10.0 branch May 27, 2026 16:28
@dotnet-policy-service dotnet-policy-service Bot modified the milestones: 10.0.10, 10.0.9 May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-validation Issues related to model validation in minimal and controller-based APIs Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants