Click here to Skip to main content
15,881,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
BACKGROUND

I've decided to try using the Visual Studio support for configuration files for the first time.

In Project->Properties->Settings I have created a bunch of application settings with the "User" scope so that I can change them at run-time.

This is working OK, but I notice that when I run the program within the Visual Studio environment, it uses a different config file than when it runs as an executable outside of VS. I can't locate either of the files responsible for this!

Example:
One of the settings is called "EngineerPassword".
If I debug the application in Visual Studio and then, at run time, I change the EngineerPassword to "hello", this setting persists when I stop debugging and start debugging again.
If I then stop debugging, and I run the executable directly, I find that the password is not "hello". I can set it to something: let's say I set it to "world". Now, when I run the application inside Visual Studio the EngineerPassword is still "hello", and when I run the executable it is "world". So clearly it is using separate config files in these scenarios.

Inside the application folder structure there is a file called app.config, but this contains the default settings which were in place when I initially created the Settings. It does not change when I change the settings at runtime.
Additionally there is an exe.config file located in the same folder as the executable. This does not change when I change the settings either.

THE QUESTION:

Which files are changing when I set new settings? Where are they located?
Posted
Comments
Kornfeld Eliyahu Peter 11-Aug-15 6:50am    
There is (or can be) a different configuration file for debug and release - you may check around to see which one you are changing...
bh_ 11-Aug-15 6:51am    
Thanks.

I have already checked around, but I cannot locate either of the files associated with debug and release. I have even widened my search to include the entire C:\ drive but I cannot find them.

That's really the point of my question - I would like to know how to locate the files.
bh_ 11-Aug-15 6:53am    
I wonder, perhaps, if the scope has anything to do with it. I have the scope set to 'User' for all my settings. Will check if this has anything to do with it after lunch.

The settings for user scope are stored here (on Win7):

C:\Users\user\AppData\Local\company\appname+somerandomcharacters

As per this CodeProject Article:

Why, Where, and How of .NET Configuration Files[^]
 
Share this answer
 
v2
These settings are cached somehow.

In the code before you read your settings place the code line:
C#
Properties.Settings.Default.Reload();


Have fun CODING
 
Share this answer
 
Comments
bh_ 11-Aug-15 8:27am    
I already have that line in my code, so that can't be it.

Aside from anything else, in my save settings code, I have this line:

Properties.Settings.Default.Save();

...which I believe writes the settings out to the file. It must be writing it somewhere, but it isn't writing it to any config files inside my project's directory.
Herman<T>.Instance 11-Aug-15 8:28am    
Are you allowed to write the file?
bh_ 11-Aug-15 9:47am    
Yep, definitely.

I have found this Code project article, which suggests that user settings get stored somewhere strange:

http://www.codeproject.com/Articles/616065/Why-Where-and-How-of-NET-Configuration-Files?fid=1836263&df=10000&mpp=25&noise=2&prof=True&sort=Position&view=Expanded&spc=Relaxed&fr=26#xx0xx

I haven't been able to verify this yet.
Herman<T>.Instance 11-Aug-15 10:07am    
Looks a valuable solution in that article
bh_ 11-Aug-15 10:20am    
Yep I have verified that the information in the article was correct.

Thank you for taking the time to help.
When running from Visual Studio, it might use the ProgName.vshost.exe.config and not the ProgName.exe.config.

See Hosting Process (vshost.exe)
 
Share this answer
 

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



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