0

Is it normal behavior of VS 2015 ?

I am trying to store a value in appSettings in App.Config. In VS 2017, it gets stored in WindowsFormsApplication1.exe.config but it's not storing the value in VS 2015

My code is the same as in both the versions of VS.

        var conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        var settings = conf.AppSettings.Settings;
        settings.Add("password", textBox1.Text);
        conf.Save(ConfigurationSaveMode.Modified);
        ConfigurationManager.RefreshSection(conf.AppSettings.SectionInformation.Name);

And my App.config is this:

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
<appSettings>

</appSettings>
</configuration>

Any explanation for this ?

Ron
  • 1,901
  • 4
  • 19
  • 38

1 Answers1

1

I believe the WindowsFormsApplication1.exe.config file that is generated when the program is built is for debugging purposes.

Try this and see what path the config file is located. (taken from this answer)

    using System.Configuration;  // Add a reference to System.Configuration.dll
    ...
    var path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
Mikael
  • 1,002
  • 1
  • 11
  • 22