Reputation: 1631
I am referring examples on internet to change settings in app.config , below is my code
string startupPath = AppDomain.CurrentDomain.BaseDirectory.Replace(@"\bin\Debug", "")+ "App.Config";
Configuration config = ConfigurationManager.OpenExeConfiguration(startupPath);
config.AppSettings.Settings.Remove("MaintainBackup");
config.AppSettings.Settings.Add("MaintainBackup", "No");
config.Save(ConfigurationSaveMode.Minimal);
Problem is , it is not updating the key values in app.config (within root directory)
But when i use
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
it update the WinApp.vshost.exe.Config in bin folder .
Question1.]- Which config file my app is picking ?
App.config in root directory
or WinApp.vshost.exe.Config in bin folder
Question 2.] If it is App.config in root directory than why it is not updating the key values
Upvotes: 0
Views: 213
Reputation: 9365
I'll try to make some order in the chaos:
There are two concepts mixed here:
App.Config is a development time file, after compilation it will become AppName.exe.config and this file will be used by your application in runtime.
vshosts.exe is an host file of Visual Studio that is intended to give better performance while debugging from visual studio.
So, While debugging your application name will be AppName.vshosts.exe and therefore the configuraion file that will be used will be AppName.vshosts.exe.config
Upvotes: 1