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

Mixed use of .NET and System.Configuration.Abstractions ConfigurationManager causes inconsistent behavior #10

Open
gavynriebau opened this issue Nov 13, 2015 · 1 comment

Comments

@gavynriebau
Copy link

When using a mix of the .NET System.Configuration.ConfigurationManager and System.Configuration.Abstractions.ConfigurationManager to retrieve and update appSettings, the returned results aren't consistent.

Here are the full steps to reproduce the problem:

Setup an App.config that contains:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="something" value="A" />
  </appSettings>
</configuration>

Create a System.Configuration.Abstractions.ConfigurationManager instance and load the app setting:

IConfigurationManager config = new ConfigurationManager();
var firstValue = config.AppSettings["something"]; // This returns "A"

Now use a .NET System.Configuration.ConfigurationManager to update the value.

var testConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
testConfig.AppSettings.Settings["something"].Value = "B";
testConfig.Save();

Then try to refresh the section and retrieve the update value using the System.Configuration.Abstractions.ConfigurationManager.

config.RefreshSection("appSettings");
var secondValue = config.AppSettings["something"]; // This returns "A" but _should_ return "B".

The above code should have returned the updated value "B" but returns the original value "A".
I've run the above scenario and confirmed the value in App.config file does get updated but I suspect the System.Configuration.Abstractions.ConfigurationManager is using a memory backed cache of app settings.

I'm not sure of the correct solution to this bug other than possible not mixing usage of System.Configuration.Abstractions.ConfigurationManager and the .NET System.Configuration.ConfigurationManager

@davidwhitney
Copy link
Owner

Interesting - I'd not really considered this scenario.

You're right, I think this counts as a bug just due to it violating the principal of least surprise - you'd expect save to work, and it doesn't.

I'm not entirely sure if it's possible / if there's even an event to hook into when regular ol' configuration manager calls "Save" though.

I'll take a look into this and see if there's something I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants