-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjectDisposedException from FileConfigurationProvider in net8.0 #96282
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionConfiguration providers might be built multiple times from the same source. Creating and disposing one provider should not "break" the source. Reproduction StepsSample user reported repro: using Microsoft.Extensions.Configuration;
var config = new ConfigurationManager() as IConfigurationBuilder;
_ = config.AddJsonFile("./appsettings.json", optional: false, reloadOnChange: true);
// workaround
//_ = config.AddJsonFile(config.GetFileProvider(), "./appsettings.json", optional: false, reloadOnChange: true);
// change properties after setting up Json config
_ = config.Properties.Remove("ConfigurationBuilderPropertiesObserverKey");
_ = config.Properties.Remove("SecretObserverExtensionsConfigurationBuilderPropertiesObserverKey"); Or even simpler (though more artificial): using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
var builder = new ConfigurationBuilder();
var jsonSource = new JsonConfigurationSource()
{
Path = "appsettings.json",
ReloadOnChange = true
};
((IDisposable)jsonSource.Build(builder)).Dispose();
_ = jsonSource.Build(builder); Expected behaviorDisposing one provider should not break others. Once the last provider is disposed from a source, that source should still be able to build more providers that function correctly. Actual behaviorAfter disposing one provider, all others are broken, and newly built providers are also broken. Regression?Yes, due to #86455 Known WorkaroundsSpecify a file provider when adding a FileConfigurationSource. For example, instead of _ = config.AddJsonFile("./appsettings.json", optional: false, reloadOnChange: true); Use this: _ = config.AddJsonFile(config.GetFileProvider(), "./appsettings.json", optional: false, reloadOnChange: true); ConfigurationCan repro in net6, net7, net8 when using the 8.0 version of Microsoft.Extensions.Configuration. Other informationNo response
|
Dup of #95745? |
thanks @vcsjones. Yes this looks the same issue. |
Description
Configuration providers might be built multiple times from the same source. Creating and disposing one provider should not "break" the source.
Reproduction Steps
Sample user reported repro:
Or even simpler (though more artificial):
Expected behavior
Disposing one provider should not break others. Once the last provider is disposed from a source, that source should still be able to build more providers that function correctly.
Actual behavior
After disposing one provider, all others are broken, and newly built providers are also broken.
Regression?
Yes, due to #86455
Known Workarounds
Specify a file provider when adding a FileConfigurationSource.
For example, instead of
Use this:
Configuration
Can repro in net6, net7, net8 when using the 8.0 version of Microsoft.Extensions.Configuration.
Other information
No response
The text was updated successfully, but these errors were encountered: