Repository navigation
Honor overridden virtual property metadata in configuration binder - #135672
Merged
rosebyte merged 4 commits intoOct 30, 2026
Merged
Conversation
Both the reflection binder and the source generator selected the base-most declaration of an overridden virtual property, discarding any [ConfigurationKeyName]/[ConfigurationIgnore] attribute applied only to the override. Combined with the reflection binder also (in some cases) separately processing the base declaration, a renamed override of a getter-only collection property could be bound twice, once under the original name and once under the renamed one. Both binders now select metadata (name/ignore) from the most-derived declaration in the override chain, falling back to a less-derived declaration only to resolve an accessor the override doesn't re-declare (e.g. a get-only override of a read-write virtual property), since invoking that accessor still dispatches virtually to the actual override at run time.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-extensions-configuration |
vladimir-aubrecht
marked this pull request as ready for review
October 13, 2026 11:45
This was referenced Oct 13, 2026
Closed
This was referenced Oct 14, 2026
rosebyte
requested changes
Oct 19, 2026
Resolve effective accessors and inherited metadata across partial property overrides, ignore unsupported indexers, and preserve PropertyInfo invocation paths to avoid argument-array allocations. Add reflection and source-generator regression coverage for the reviewed edge cases.
rosebyte
reviewed
Oct 20, 2026
Resolve effective accessors and inherited property metadata once during property discovery, then reuse sparse cached data throughout binding. Use targeted non-indexer property lookups to avoid repeated hierarchy-wide property array allocations.
svick
pushed a commit
that referenced
this pull request
Nov 17, 2026
…at cannot inherit attributes (#136899) Fixes #136759 This is a targeted mitigation for `release/11.0`. Main already avoids this lookup following [#135672](#135672), which also changes overridden-property handling. This PR preserves 11.0's binding behavior rather than backporting that broader change. When an attribute is not declared directly, reflection retrieves attribute-usage metadata and prepares a parent-property lookup before discovering that the property cannot inherit. The binder therefore pays this cost for ordinary nonvirtual properties and virtual properties that introduce a new slot. This change checks the getter and setter's virtual-slot flags first. If neither accessor can inherit, it uses direct attribute lookup. Potential overrides retain the existing inherited lookup. The shared helper covers both property binding and constructor/property matching. No caching is added. An equivalent early rejection in reflection remains a possible future improvement, but requires a runtime update. The binder-local mitigation also benefits applications updating the package on an existing runtime. # Regression The additional lookup was introduced with `ConfigurationIgnoreAttribute` in [#126396](#126396). This change retains that feature while removing unnecessary inheritance work. Measured on .NET 10.0.14, macOS arm64, with dependencies held constant. Mean time per operation: | Operation | Binder 10.0 | Affected 11.0 source | Patched | |---|---:|---:|---:| | `Get<T>`, 1 plain property | 0.237 us | 0.591 us | 0.261 us | | `Get<T>`, 10 plain properties | 1.672 us | 5.375 us | 1.913 us | | `Get<T>`, 50 plain properties | 9.403 us | 27.642 us | 10.299 us | | Repeated `Bind`, 50 plain properties | 9.074 us | 28.874 us | 10.321 us | | Fresh-scope snapshot, 50 plain properties | 9.423 us | 28.611 us | 10.752 us | For 50-property plain `Get<T>`, allocation decreases from 27,611 bytes to 17,553 bytes, compared with 17,552 bytes for Binder 10.0. The displayed cases remain approximately 10–15% slower than Binder 10.0. # Risk Expected compatibility risk is low: inherited lookup is bypassed only when neither accessor can inherit. Property discovery, constructor selection, and options lifetimes are unchanged. --------- Co-authored-by: Copilot App <223556219+Copilot@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.
Summary
ConfigurationKeyNameandConfigurationIgnoremetadata from the most-derived declaration of an overridden virtual property.This correctness fix is split from #134424 so that override metadata handling can be reviewed independently from property-level
TypeConverterAttributesupport.Testing
Microsoft.Extensions.Configuration.Binder.Tests: 364 passedMicrosoft.Extensions.Configuration.Binder.SourceGeneration.Tests: 436 passed, 28 skippedNote
This pull request description was generated with assistance from GitHub Copilot.