简体   繁体   中英

System.Collections.Specialized.StringDictionary is not retaining saved settings after application restart

I am trying to use the System.Collections.Specialized.StringDictionary to save paired values in to settings.settings file.

I run my application, updated the Settings, did Settings.Default.Save() and when started the app again noticed the new settings did not work!

Looking in the created user.config, the StringDictionary was serialized to <value /> .

Please suggest me if there is any alternative or work around to make this work.

@kns provided the solution for me. I just added the line [global::System.Configuration.SettingsSerializeAs(global::System.Configuration.SettingsSerializeAs.Binary)] above the StringDictionary property in the Settings.Designer.cs file as follows:

[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;
        }
    }

where customSetPhrases is the name of my setting. This seems to have done the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM