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 part开发者_开发技巧icular 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.
精彩评论