C# – Why are the application settings not getting persisted

application-settingscnet

So I have some settings that are of the user scope, but for some reason, they are not being saved to the .exe.config file. I do the following:

Properties.Settings.Default.Email = "new@value.com";
Properties.Settings.Default.Save();

Yet I look at the settings file in the debug folder and it is still the default that I set in visual studio. Am I doing this wrong?

Best Answer

User settings are specific to the user, so they wouldn't get saved back to the .exe.config file, which is system wide.

From the docs of LocalSettingsProvider:

Application-scoped settings and the default user-scoped settings are stored in a file named application.exe.config, which is created in the same directory as the executable file. Application configuration settings are read-only. Specific user data is stored in a file named username.config, stored under the user's home directory.

So for a UserSettingsTest application just run from VS under the debugger (hence the vshost bit) I ended up with a path of:

C:\Users\Jon\AppData\Local\UserSettingsTest
  \UserSettingsTest.vshost.e_Url_pdqoppugkz1vaawbhwkkcu5ibxpi2fgu
  \1.0.0.0\user.config