【问题标题】:System.Collections.Specialized.StringDictionary is not retaining saved settings after application restartSystem.Collections.Specialized.StringDictionary 在应用程序重新启动后不保留保存的设置
【发布时间】:2015-01-14 06:35:14
【问题描述】:

我正在尝试使用 System.Collections.Specialized.StringDictionary 将配对值保存到 settings.settings 文件中。

我运行我的应用程序,更新了设置,做了 Settings.Default.Save() 当再次启动应用程序时,发现新设置不起作用!

查看创建的 user.config,StringDictionary 被序列化了 到<value />

如果有任何替代方案或解决方法可以使这项工作发挥作用,请建议我。

【问题讨论】:

  • 不使用VS调试器运行exe会怎样?
  • @kennyzx :感谢您的回复。通过直接从 bin\debug 文件夹运行 .exe 尝试仍然行为与上述相同。即,直到应用程序重新启动,值才会被保存并显示回来,但是当我重新启动 exe 时,所有存储的值都消失了。请注意这里总是配置文件只显示 标签。
  • 我可以通过这种方式解决它;SerializeAs.Binary 有诀窍。在 settings.designer.cs 文件的 StringDictionary 属性之上添加了 [SettingsSerializeAs(SettingsSerializeAs.Binary)]。跨度>
  • 您可以发布答案以分享您的发现,并将其标记为已接受的答案。

标签: c# settings.settings


【解决方案1】:

@kns 为我提供了解决方案。我只是在Settings.Designer.cs 文件中的StringDictionary 属性上方添加了[global::System.Configuration.SettingsSerializeAs(global::System.Configuration.SettingsSerializeAs.Binary)] 行,如下所示:

[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.SettingsSerializeAs(global::System.Configuration.SettingsSerializeAs.Binary)]
public global::System.Collections.Specialized.StringDictionary customSetPhrases {
 get {
            return ((global::System.Collections.Specialized.StringDictionary)(this["customSetPhrases"]));
        }
        set {
            this["customSetPhrases"] = value;
        }
    }

customSetPhrases 是我设置的名称。这似乎成功了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    相关资源
    最近更新 更多