Changes to App.Config file are not reflected?

kaisersoze

Centurion
Joined
Aug 27, 2003
Messages
152
In my Application I make changes to some parameters in App.Config file.
In the next method I try to read the parameters to show the changed values to the user. If I manually open the config file I see the changes but, the application is not able to see the changed variables. It is always showing the previous values. But, If I close and restart the application, then new values are seen.

What am I missing, an how to show the new values.
 
The App.Config file is a "helper" by Visual Studio - I don't know the real name, but that's what I call it. Behind the scenes, when you build your project it copies the current app.config from the "root" folder of your project to the \bin\Debug folder (or whatever release/folder you use). It also renames it to the proper name - the name matches the assembly plus a config extension. So for an EXE project named "Test.exe" you'll have "Test.exe.config".

If you want to make changes while the app is running, you'll have to modify this file - open it manually in notepad (or even Visual Studio). Every time you rebuild the file will be replaced by Visual Studio with the values in the app.config file so don't forget to put your changes back in the app.config file.

-ner
 
To add on what Nerseus said, changes made to the Test.exe.config require the application to restart to be effective through the normal way. However, nothing stops you from manually reading the file.
 
Yes, I mean test.exe.config file and even thou i am reading manually from the config file the values are still the old. but once I restart the application the values are changing. by any way using reflections of anything can i change the values in the same instance.
 
How are you writing to this file?
I am trying the following without success:

Code:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.AppSettings.Settings["MySetting"].Value = "newVal";
                config.Save(ConfigurationSaveMode.Modified,true);
                ConfigurationManager.RefreshSection("appSettings");

I don't see the change in either the file or the code.
Are ya'll saying that there is no way to make changes to appSettings and have them persist?
I had all of my settings in an external xml file and i was reading and writing them that way but I thought this is the way we were supposed to do it for 2.0?
 
Back
Top