我正在尝试在运行时保存一些数据:
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,我打开此文件并手动写入设置。之后,我运行上面提到的代码并得到此异常:
Item has already been added. Key in dictionary: 'tab' Key being added: 'tab'
为什么Settings.Default.Save()
代码不起作用?
最佳答案
您没有说明您的设置是用户范围内的还是应用程序范围内的。设置文件的保存位置会有所不同。听起来好像您的设置是用户范围,并且您正在应用程序设置文件中查找它们。异常是设置已经存在的线索。查看此问题/答案以获取更多信息。 When using a Settings.settings file in .NET, where is the config actually stored?
关于c# - 在 Settings.settings 中保存属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13170535/