Skip to content
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

Closed
ericstj opened this issue Dec 22, 2023 · 3 comments
Closed

ObjectDisposedException from FileConfigurationProvider in net8.0 #96282

ericstj opened this issue Dec 22, 2023 · 3 comments

Comments

@ericstj
Copy link
Member

ericstj commented Dec 22, 2023

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:

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 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

_ = config.AddJsonFile("./appsettings.json", optional: false, reloadOnChange: true);

Use this:

_ = config.AddJsonFile(config.GetFileProvider(), "./appsettings.json", optional: false, reloadOnChange: true);

Configuration

Can repro in net6, net7, net8 when using the 8.0 version of Microsoft.Extensions.Configuration.

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 22, 2023
@ghost
Copy link

ghost commented Dec 22, 2023

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

Issue Details

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:

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 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

_ = config.AddJsonFile("./appsettings.json", optional: false, reloadOnChange: true);

Use this:

_ = config.AddJsonFile(config.GetFileProvider(), "./appsettings.json", optional: false, reloadOnChange: true);

Configuration

Can repro in net6, net7, net8 when using the 8.0 version of Microsoft.Extensions.Configuration.

Other information

No response

Author: ericstj
Assignees: -
Labels:

untriaged, area-Extensions-Configuration

Milestone: -

@vcsjones
Copy link
Member

Dup of #95745?

@tarekgh
Copy link
Member

tarekgh commented Dec 26, 2023

thanks @vcsjones. Yes this looks the same issue.

@tarekgh tarekgh closed this as completed Dec 26, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Dec 26, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants