Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i try to edit app.config file and my code is :
C#
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["a"].Value = "kkkk";
 config.Save(ConfigurationSaveMode.Modified);           ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);


and app.config file is :
HTML
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  <appSettings>
    <add key="a" value="b" />
  </appSettings>
</configuration>


when i run my solution vshost.exe.config changed in runtime but when i stop my solution my values in vshost.exe.config come back again

i unchecked "enable the visual studio hosting process" in properties
now just exe.config changed but vshost.exe.config not changed

how can i change both exe.config and vshost.exe.config on "runtime"
Posted
Updated 12-Sep-17 18:06pm

the vshost.exe.config file changes when your run the vshost.exe file. Whenever you are running your application in debug mode from visual studio the vshost.exe is executed that is the reason why the vshost.exe.config file is changing when your code to modify the config file was run. but as soon as you stop and rerun your application Visual studio replaces the vshost.exe.config file with your exe.config file so your changes in vshost.exe.config file will be lost. Don't worry about this as in actual scenario your exe file will re used to launch your application and not your vshost.exe.

So try to run the application directly from folder from exe. and this will modify the exe.config file only.
 
Share this answer
 
my data formet restor your data
 
Share this answer
 
Comments
Graeme_Grant 13-Sep-17 0:18am    
Is this supposed to be a question or an answer?

This question is OVER 3-YEARS-OLD and already has an answer accepted! Please do not post solutions to tombstoned (old) questions & questions where answers are already accepted. There are plenty of other "current" questions waiting for help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900