I’m trying to Serialize some Object, that contain an IList with Children Elements. The IListis non-generic and i cannot just make it at generic one.
I get the exception like “The Type MyObjectChild was not expected. …” and it says something about XMLInclude, but i don’t think thats what I’m searching.
Does anyone have any idea how bring XMLSerialzer to serialize the child elements as well?
Both Elements are [Serializable]
XmlSerializer xmlSerializer = new XmlSerializer(typeof ObservableCollection<MyEntryViewItem>));
FileStream fileStream = new FileStream(exportPath, FileMode.Create);
xmlSerializer.Serialize(fileStream, _listEntries);
public IList ElementChildren { get { return _item.Children; } set { _item.Children = value; RaisePropertyChanged(() => ElementChildren); } }
[Serializable]
public sealed class ElementChild
{
private int _id;
private string _text;
private string _path;
...
}
According to Simon Hewitt you can just use the
XmlIncludeto specify the type of your list. An alternative can be found at roboxman.wordpress.com