Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,25 @@ internal static bool TryGetConfiguration(this IConfigurationRoot root, string ke
for (int i = providers.Count - 1; i >= 0; i--)
{
IConfigurationProvider provider = providers[i];
if (provider.TryGet(key, out value))

try
{
if (provider.TryGet(key, out value))
{
return true;
}
}
catch (ObjectDisposedException)
{
return true;
// Skip disposed providers to avoid exceptions during access.
// This is especially relevant for cases like ConfigurationManager,
// which implements IConfigurationRoot and may dispose providers
// if configuration sources are concurrently modified. A new collection
// is created in this case, so it's still safe to iterate over it.
//
// If we want to avoid this possible exception altogether, we could update
// ConfigurationSection.TryGetValue to be virtual and have ConfigurationManager
// implement it with reference counting like it does for the indexer.
}
}

Expand Down
Loading