0
Saving useful information to config file is cool. Doing that during runtime is even cooler. If that information suddendly disappears isn’t cool at all.
I was saving some data to configuration file (app.config) at runtime. Visual studio copied app.config file before application runs to Debug folder (or any other folder if you want to, i used default settings for my Debug build), then renamed it to my_application_name.vshost.exe.config. It did that because that’s what it does to config file, when running application it copies it to running folder, then renames it according to pattern application_name.application_extension.config.
As you can see, there is also string vshost in my configuration name, that is because i was running it in visual studio using debugger. So i wasn’t running file my_application_name.exe but instead visual studio ran file my_application_name.vshost.exe. So my config was written in my_application_name.vshost.exe.config file. Nothing wrong with that.
The funny thing is that after i closed my application all data from my config file disappeared. Well almost all of my data. Data included in my App.config file remained, so actually only data entered in config at runtime disappeared. What i figured out when trying to solve this problem is that vshost config file gets copied from normal application config file (my_application.exe.config) ! Because my_application.exe.config was exact copy of App.config file it seemed as if my runtime settings disappeared.
The solution to this problem is that you have to right click in Visual studio on project name, then click properties and in Debug tab remove setting Enable Visual studio hosting process. Then run application and this time it will put settings to application_name.extension.config file. When you close application, settings will not disappear. Then if you want to use debugger, turn EnableVisual studio hosting process settings back on and settings you entered when hosting process was turned on will remain in file (vshost config file).
And that can be useful piece of information to have if you are trying to save something to configuration file at runtime if you’re using Visual studio and trying to figure out why your precious configuration data is disappearing all over the place.