Skip to content

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Jul 11, 2025

Fixes #117491

@Copilot Copilot AI review requested due to automatic review settings July 11, 2025 18:04
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 adds protection against ObjectDisposedException when iterating through configuration providers, ensuring disposed providers are skipped instead of propagating exceptions.

  • Wraps the provider.TryGet call in a try/catch for ObjectDisposedException
  • Adds explanatory comments for skipping disposed providers
Comments suppressed due to low confidence (2)

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

  • Add a unit test that disposes a provider mid-enumeration to verify that ObjectDisposedException is correctly caught and the provider is skipped.
                try

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

  • Iterating directly over the providers list while it can be mutated by ConfigurationManager may lead to an InvalidOperationException. Consider capturing a snapshot (e.g., var snapshot = providers.ToList()) before the loop to avoid collection modification issues.
            for (int i = providers.Count - 1; i >= 0; i--)

@tarekgh tarekgh added this to the 10.0.0 milestone Jul 11, 2025
@tarekgh tarekgh requested a review from halter73 July 11, 2025 18:05
…onfigurationRootExtensions.cs

Co-authored-by: Stephen Halter <[email protected]>
@tarekgh tarekgh merged commit 645d049 into dotnet:main Jul 12, 2025
86 of 88 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix regression which could cause ODE during configuration binding
2 participants