John John - 2 months ago 11
Vb.net Question

Where do my settings go?

I am having a tough time trying to figure out where my settings are going. I am retaining a connection string which I can not find anywhere. So far I learned that AppName.vshost.exe.config is supposed to be the debug version and AppName.exe.config is supposed to be the release but that is not the case or if it is then they are not going to thier default folders nor the folder I chose. I do not know if I did something wrong or this is a Microsoft "feature" but if anyone has a clue please fill me in.

I am developing on a Win 7 machine with VS 2015. My build - Configuration is "Active (Debug)" and I have set the Output path to "C:\Bin" because I have other libraries I am building that are required by this app and its easier to just set all the output paths to the same place.

To try to find the issue I made a new setting, Test:
enter image description here

I also added a textbox to the form and use it like so:

public Main()
{
...
textBox1.Text = Settings.Default.Test;
...
}

private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
...
Settings.Default.Test = textBox1.Text;
...
}


I then compiled and copied the exe and required dlls from C:\Bin to C:\Test. There isn't any config file in that directory.

The form comes up with a "T" in the text box. So far so good. I then change it to "EXE-Test":
enter image description here

I close it and re-open it and my change is there. But where does it go? There is no config file created in the folder where I run it from like I would expect.
Both the SQLgem.vshost.exe.config and SQLgem.exe.config files have the original "T" in them in my output folder (C:\Bin).
enter image description here

C:\Code\SQLgem\SQLgem\bin\Release has nothing in it, which is what I expected since I did not build a release. C:\Code\SQLgem\SQLgem\bin\Debug just has shells, the new setting (actually all my settings) do not appear there.

And it gets even odder. When I run in debug (visual studio) and change the "T" to debug it persists. So where does this one go?

enter image description here

So now there are two settings that persist but I can not find anywhere. Doing a C:> dir SQLgem.exe.config /s does not find any more than the ones I already mentioned.

Where can they be?

Somehow "Hewlett-Packard Company" became the company in the embedded information. So when I was following the first post and checked both locations I instinctively ignored the folder that was not my company. Upon furhter investigation I finally found them!

Answer

Those are user-scope settings, not application-scope, so they won't be persisted back to app.exe.config in the bin directory (which is often C:\Program Files and not writable by the user).

Somewhere under %LOCALAPPDATA% (which is user-writable) you'll find the settings stored in a file named user.config.

The directory this file is in is influenced by your assembly metadata, such as Company Name and Product Name and Version.

Comments