I was trying to serialize a list of objects to my user.settings file. I've tried a lot of things, and the only thing I got to work was the solution here. Add a collection of a custom class to Settings.Settings I tried many different things, but this one was the only one that consistently worked.
Edit: What I am trying to serialize is either a List of objects (of a serializable class), or just a list of Tuples
The solution looks like this:
public class Favorites: ApplicationSettingsBase
{
[UserScopedSetting()]
[SettingsSerializeAs(System.Configuration.SettingsSerializeAs.Binary)]
[DefaultSettingValue("")]
public System.Collections.ArrayList FavoritesList
{
get
{
return ((System.Collections.ArrayList)this["FavoritesList"]);
}
set
{
this["FavoritesList"] = (System.Collections.ArrayList)value;
}
}
}
Technically, it works. However, I wanted to get it to work as XML serialization, not as binary. Switching over to SettingsSerializeAs.Xml, it doesn't serialize the settings, all I get are an empty tag for these settings. Do I have to do it differently when I serialize settings as XML?