C# settings being loaded from .exe.config but are saved to user.config

1k views Asked by At

For some reason when my application loads it reads the settings from programname.exe.config in the application path, but when I call Properties.Settings.Default.Save() the settings are saved in Appdata/local/program/version/user.config
How do I get my application to load from user.config?

If I delete programname.exe.config, its regenerated next time the program is run.

settings

programname.exe.config and user.config

2

There are 2 answers

1
Dhanuka777 On

You need to do this,

Properties.Settings.Default.Upgrade()

before the save.

0
Yogi On

This is the legitimate behavior. The User settings are specific to user, and therefore saved in user profile. Imagine where a user customize some setting for him, and they are being overridden by some other user. It will not be a good user experience certainly.

The loading of user settings would be same.

For example you have a UserSetting called quality, you can read this setting like -

var qualitySettingValue = Properties.Settings.Default.quality;

...and you can modify this value and save the new settings like -

Properties.Settings.Default["quality"] = "New Quality Settings";
Properties.Settings.Default.Save();

Now next time when you read this value like this -

var qualitySettingValue = Properties.Settings.Default.quality;

qualitySettingValue will have the updated value -

Application level settings on the other hand are common to all users, will be saved in Application.exce.config file.