2

I'm trying to save some data at the runtime:

SettingsProperty property = new SettingsProperty("tabSetting");
property.Name = "tab";
property.PropertyType=typeof(string);
property.DefaultValue = "path";
Settings.Default.Properties.Add(property);
Settings.Default.Save();

but this code don't save any changes in file Settings.settings.

Also I try to make changes in Settings.settings from VisualStudio, I open this file and write settings by hand. After that I run the code which is mentioned above and get this exeption:

Item has already been added. Key in dictionary: 'tab'  Key being added: 'tab'

Why Settings.Default.Save() code is not working?

Mikhail Sokolov
  • 546
  • 1
  • 7
  • 18

1 Answers1

2

You don't say if your settings are user, or application in scope. It makes a difference in where your settings file is saved. Is sounds as if your settings are User scope and you are looking for them in the application settings file. The exception is a clue the setting already exists. Look at this question / answer for more information. When using a Settings.settings file in .NET, where is the config actually stored?

Community
  • 1
  • 1
jac
  • 9,666
  • 2
  • 34
  • 63