简体   繁体   中英

Settings end up in user.config even though they are unmodified as read from app.config

Consider a C# app which has a number of user settings, some are actively used and updated and others are always read-only. Under which circumstances can such a read-only settings property end up in a per user maintained user.config?

I am seeing a funny behavior that several user configuration settings that app merely reads end up in user.config with the same unmodified default values. My app is versioned so when next version is deployed and some of the read-only settings are changed by design, they don't get picked up by the new version because ApplicationSettingsBase.Upgrade() picks local outdated values.

Basically, if the app never modifies a particular settings property, how and why does it end up in user.config?

Additionally, how can I fix the damage and erase existing read-only properties from user.config at future upgrades?

Without seeing the code that saves the properties in the user.config file I can only guess, but I would suggest that you've got some code that writes these values regardless of whether they've changed from the default, or even if they can change from the default.

Have you got something like:

Properties.Settings.Default.Property1 = this.SomeValue;
Properties.Settings.Default.Property2 = this.ReadOnlyValue;
Properties.Settings.Default.Save();

As for your addition question, I think that the Save overwrites the existing file rather than just updating it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM