【问题标题】:Saving properties in Settings.settings在 Settings.settings 中保存属性
【发布时间】:2012-10-21 15:42:16
【问题描述】:

我正在尝试在运行时保存一些数据:

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() 代码不起作用?

【问题讨论】:

标签: c# .net visual-studio-2010 properties settings


【解决方案1】:

您没有说您的设置是用户还是范围内的应用程序。它会影响您的设置文件的保存位置。听起来好像您的设置是 User 范围,并且您正在应用程序设置文件中寻找它们。例外是设置已经存在的线索。查看此问题/答案以获取更多信息。 When using a Settings.settings file in .NET, where is the config actually stored?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多