4

Assuming there are 5 items in the settings file (MySetting1 to MySetting5), why does PropertyValues have 0 items while Properties has the correct number?

Console.WriteLine( Properties.Settings.Default.PropertyValues.Count); // Displays 0
Console.WriteLine( Properties.Settings.Default.Properties.Count);     // Displays 5
MaKCbIMKo
  • 2,740
  • 1
  • 21
  • 27

1 Answers1

6

It appears that PropertyValues refers to the number of PropertyValues that have been set. The default values you specify aren't considered set and won't be stored to the user config if you sall Save().

Console.WriteLine(Settings.Default.PropertyValues.Count.ToString());
Console.ReadLine();
Settings.Default.Setting = "abc";
Console.WriteLine(Settings.Default.PropertyValues.Count.ToString());
Console.ReadLine();

results in the following output:

0

1

James
  • 3,292
  • 1
  • 19
  • 15
  • It appears it's enough to do this: Settings.Default.Setting = Settings.Default.Setting; –  Sep 18 '08 at 01:43
  • 2
    _"It appears that PropertyValues refers to the number of PropertyValues that have been set"_ -- that's not quite right, as all you have to do is _retrieve_ a property value to force the `PropertyValues` collection to be populated. Seems like a bug in .NET to me, as this doesn't appear to be documented behavior. – Peter Duniho Aug 01 '19 at 00:52