views:

75

answers:

1

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?

A: 

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.

ChrisF
I have only "var x = Settings.Default.Property1", nothing more, nothing less. Property1 is basically just read once. Somehow it ends up in user.config. I know very well the purpose of this property so I am sure it is not written to anywhere which I have also checked both with dumb search and using Resharper.One thing where I might have made a mistake is often changing app.config during development without reflecting changes in either Settings.settings or Settings.Designer.cs. This boils down to having DefaultSettingValueAttribute with the previous value. Can this be that important?
wpfwannabe