kns
kns

Reputation: 43

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.

Upvotes: 1

Views: 1103

Answers (1)

saddin
saddin

Reputation: 1

@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.

Upvotes: 0

Related Questions