Skip to content

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Jul 9, 2025

Fixes #117444
Fixes #117445
Fixes #117469

We recently made a change #116677 to support null values in configuration. Initially, the code was performing the configuration value lookup in the order the providers are stored in the root configuration object. However, to align with standard behavior, the lookup should occur in reverse order, as that's how configuration resolution typically works.

I've manually verified the fix against all reported issues and added a test case to cover this previously missed scenario.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

@tarekgh tarekgh requested a review from ericstj July 9, 2025 19:31
@tarekgh
Copy link
Member Author

tarekgh commented Jul 9, 2025

CC @halter73

@tarekgh tarekgh marked this pull request as ready for review July 9, 2025 19:40
@Copilot Copilot AI review requested due to automatic review settings July 9, 2025 19:40
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adjusts the configuration lookup so that the most recently added provider takes precedence by iterating providers in reverse, and adds a unit test to verify that missing keys in later providers don’t override earlier values.

  • Reverse the provider enumeration in TryGetConfiguration to align with standard override semantics.
  • Introduce TestProvidersOrder to ensure missing keys in the last provider retain earlier values.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/libraries/Microsoft.Extensions.Configuration/src/InternalConfigurationRootExtensions.cs Change TryGetConfiguration to build an IList and loop providers in reverse order.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs Add TestProvidersOrder unit test to validate provider precedence when keys are missing.
Comments suppressed due to low confidence (3)

src/libraries/Microsoft.Extensions.Configuration/src/InternalConfigurationRootExtensions.cs:45

  • [nitpick] The comment could be expanded to explain why reverse iteration is needed (last-added provider wins), which will help future maintainers understand the rationale.
            // common cases Providers is IList<IConfigurationProvider> in ConfigurationRoot

src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs:3012

  • [nitpick] The test name TestProvidersOrder is generic; consider renaming to something like GetConfiguration_UsesLastProviderValueUnlessKeyMissing to clearly convey behavior under test.
        public void TestProvidersOrder()

src/libraries/Microsoft.Extensions.Configuration.Binder/tests/Common/ConfigurationBinderTests.cs:3012

  • Add an additional test where a later provider explicitly sets a key to null, verifying that null correctly overrides earlier non-null values as intended by the null-support change.
        public void TestProvidersOrder()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.