Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

<appSettings> in file myapplication.exe.config getting overwritten everytime I start my app.


I use the appsettings section of the config file to store local application variables.  They get written fine during my app (I can check the contents while the app is running and all is fine) but as soon as I stop my app. and then invoke it again the .config file is reset all my settings are gone!  All that's left is the basic structure with my sql connection line.

I am currently running this in debug mode and what seems to be happening is that when I update my myapplication.exe.config file this is is done in the debug folder, however, each time my app runs a file called app.config, in my vs.net solution folder, is copied into the debug folder overwritting my newly updated .config file!

Why / which file should I be updating??????

Any thoughts.

Many thanks.

  • 3
2 Solutions
As I know app.config file should store configuration parameters for program executing.
I suggest to save your local variables in other file (Xml, for example) or in the registry.

JAMESAuthor Commented:
As far as I am aware Microsoft are trying to push users towards storing local app. settings in this file so it's a bit annoying they make it so hard!

I want to avoid the registry and are already looking at using another config file but I wondered if there was a reason why my problem exists and, therefore, a solution!

Thanks anyway.
Fahad MukhtarDistinguished EngineerCommented:
Because each time you save settings to your config file, the new entries are written to the debug\bin\Appconfg.config
this file is overwritten each time when you run your application from VD.Net IDE.
When you will run your app directly from bin folder, it wont happen . Also this wont happen if you are going to deploy your app.
The only solution to this is to have a separate xml file
JAMESAuthor Commented:
Ok - neither of you really solved my problem just reiterated what I had already discovered and mentioned but at least I am now sure it's not something I am doing wrong.

I hope you both don't mind if I split the points.

Thanks for your input.
JAMESAuthor Commented:

The solution i did use was that in my app.config class I wrote I use a condition to check if I am in debug mode - if I am I write to the app.config of the solution folder in addition to my myapplication.exe.config file.

That way when the program starts within vs.net it copies the file as usual but this time it now contains the values i previously stored!


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now