我正在尝试在运行时保存一些数据:
SettingsProperty property = new SettingsProperty("tabSetting");
property.Name = "tab";
property.PropertyType=typeof(string);
property.DefaultValue = "path";
Settings.Default.Properties.Add(property);
Settings.Default.Save();但此代码不会在文件Settings.settings中保存任何更改。
此外,我还尝试在VisualStudio中对Settings.settings进行更改,我打开此文件并手动编写设置。在那之后,我运行上面提到的代码,并得到这个exeption:
Item has already been added. Key in dictionary: 'tab' Key being added: 'tab'为什么Settings.Default.Save()代码不能工作?
发布于 2012-11-01 11:47:58
您没有说明您的设置是用户还是范围内的应用程序。设置文件的保存位置会有所不同。听起来好像您的设置是User scope,并且您正在应用程序设置文件中查找它们。例外情况是设置已经存在的线索。有关更多信息,请查看此问题/答案。When using a Settings.settings file in .NET, where is the config actually stored?
https://stackoverflow.com/questions/13170535
复制相似问题