ak112358
ak112358

Reputation: 713

Using a ListDictionary Class setting (Settings.settings)

In my C# program (.net v4, MS Visual C# Express) I am attempting to use a setting of the class ListDictionary.

Here's my test code:

// String setting
Properties.Settings.Default.StringTest = "Llama llama LLAMA!";

// ListDictionary setting
ListDictionary ld = new ListDictionary();
ld.Add("key1", "llama");
ld.Add("key2", "alpaca");

Properties.Settings.Default.LDTest = ld;

// Save settings
Properties.Settings.Default.Save();

After executing my code, the user.config file is written with the string setting, but not with the ListDictionary setting (excerpt):

    <setting name="StringTest" serializeAs="String">
        <value>Llama llama LLAMA!</value>
    </setting>
    <setting name="LDTest" serializeAs="Xml">
        <value />
    </setting>

List Dictionary is listed as being serializable here, but is there some manual work I need to do to get it into a setting file? Furthermore, is there any way to figure out what classes/types are able to be used as settings and which are not?

Upvotes: 2

Views: 1944

Answers (1)

Ritch Melton
Ritch Melton

Reputation: 11598

Make sure you have Break When Exceptions thrown enabled, as well as .Net Framework Source Stepping if you want see this exception. While I don't think you want to serialize complex datatypes to the Settings.settings file, you could serialize this to a string separated by semicolons and commas if you were really dead set on doing this.

Make sure you have Break When Exceptions thrown enabled

Upvotes: 1

Related Questions