-
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
Wrong disposal of FileConfigurationSource.FileProvider by FileConfigurationProvider.Dispose() on a modification of ConfigurationManager.Sources #95745
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionThis is a regression in .NET Core 8 from .NET Core 7 caused by commit 63fad3c36fdf36e31ab0dd4c7e32732750390c4a The lifetimes of However, Reproduction StepsSee the attached repro.
Expected behaviorModification of Actual behaviorModification of Regression?Yes, it's a regression from .NET Core 7, per the description above. Known WorkaroundsThere is no workaround. ConfigurationA simple "ASP.NET Core Web App (Razor Pages)" from a standard Visual Studio template with .NET 8. Other informationNo response
|
Tagging subscribers to this area: @dotnet/area-extensions-filesystem Issue DetailsDescriptionThis is a regression in .NET Core 8 from .NET Core 7 caused by commit 63fad3c36fdf36e31ab0dd4c7e32732750390c4a The lifetimes of However, Reproduction StepsSee the attached repro.
Expected behaviorModification of Actual behaviorModification of Regression?Yes, it's a regression from .NET Core 7, per the description above. Known WorkaroundsThere is no workaround. ConfigurationA simple "ASP.NET Core Web App (Razor Pages)" from a standard Visual Studio template with .NET 8. Other informationNo response
|
@cristalink big thanks for a very detailed bug report and apologies for missing the issue. Before I come up with a fix I can provide a workaround: create Example: PhysicalFileProvider fileProvider = new(Path.GetDirectoryName(filePath));
JsonConfigurationProvider configurationProvider = new(new JsonConfigurationSource()
{
Path = filePath,
FileProvider = fileProvider
});
IConfigurationRoot config = new ConfigurationBuilder()
.AddJsonFile(configurationProvider.Source.FileProvider, filePath, optional: true, reloadOnChange: false)
.Build(); Explanation: user provided providers are not disposed by Lines 166 to 168 in ffb2578
|
Description
This is a regression in .NET Core 8 from .NET Core 7 caused by commit 63fad3c36fdf36e31ab0dd4c7e32732750390c4a
The lifetimes of
FileConfigurationSource
andFileConfigurationProvider
are different.FileConfigurationSource
as an entry inConfigurationManager.Sources
has potentially a longer lifetime than associatedFileConfigurationProvider
. The latter gets disposed and recreated on virtually every modification ofConfigurationManager.Sources
, includingInsert()
,Remove()
,RemoveAt()
, etc. Such a modification causes a call toConfigurationManager.ReloadSources()
and, in turn, toReferenceCountedProviderManager.ReplaceProviders()
that disposesFileConfigurationProvider
.However,
FileConfigurationProvider.Dispose()
, contrary to the good practices of OOP, disposes alsoFileConfigurationSource.FileProvider
. This may result inFileConfigurationSource
with permanently disposedFileProvider
remaining inConfigurationManager.Sources
. A further modification ofConfigurationManager.Sources
may cause access to disposedFileConfigurationSource.FileProvider
and thus toObjectDisposedException
.Reproduction Steps
See the attached repro.
WebApplication1.zip
Expected behavior
Modification of
ConfigurationManager.Sources
should not adversely affect the configuration sources remaining on the list.Actual behavior
Modification of
ConfigurationManager.Sources
wrongly causes the disposal ofFileConfigurationSource.FileProvider
.Regression?
Yes, it's a regression from .NET Core 7, per the description above.
Known Workarounds
There is no workaround.
Configuration
A simple "ASP.NET Core Web App (Razor Pages)" from a standard Visual Studio template with .NET 8.
Other information
No response
The text was updated successfully, but these errors were encountered: