[release/10.0] Skip indexer properties in validation source generator#65458
Open
github-actions[bot] wants to merge 2 commits intorelease/10.0from
Open
[release/10.0] Skip indexer properties in validation source generator#65458github-actions[bot] wants to merge 2 commits intorelease/10.0from
github-actions[bot] wants to merge 2 commits intorelease/10.0from
Conversation
DeagleGross
approved these changes
Feb 18, 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.
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 withAddValidation()enabled. The generator emits indexer properties (this[]) asValidatablePropertyInfoentries, but at runtimeDeclaringType.GetProperty("this[]")returns null because reflection names indexers"Item", causing:The fix adds
member.IsIndexer(plus defensive checks for static, write-only, and non-public-getter properties) to the existing skip filter inExtractValidatableMembers. These are not meaningful targets for data annotation validation.Fixes #65424
Customer Impact
Customer reported. Using
JsonElement,JsonDocument, orDictionary<,>as minimal API parameters withAddValidation()causes an unhandledInvalidOperationExceptionat runtime. No workaround exists other than avoiding these common types or disabling validation entirely.Regression?
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
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
All 27 generator tests pass, including 2 new tests:
SkipsIndexerPropertiesOnTypesandSkipsNonReadableAndStaticProperties.Packaging changes reviewed?