Skip to content

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

Open
github-actions[bot] wants to merge 2 commits intorelease/10.0from
backport/pr-65432-to-release/10.0
Open

[release/10.0] Skip indexer properties in validation source generator#65458
github-actions[bot] wants to merge 2 commits intorelease/10.0from
backport/pr-65432-to-release/10.0

Conversation

@github-actions
Copy link
Contributor

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

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.

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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments