Hopefully this question isn't too obvious, however I'm taking my first steps into the topic of serialization and couldn't find an explanation for the following behaviour:
I wanted to serialize a class to test if I set up everything correctly. For this I took the code from this tutorial and adapted it as follows:
private void SerializePresets(string path)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(MyClass));
using (TextWriter writer = new StreamWriter(path))
{
xmlSerializer.Serialize(writer, this);
}
}
This method lies within MyClass
and is also called from there. This gives me the following exception:
An exception of type 'System.InvalidOperationException' occurred in System.Xml.dll but was not handled in user code
Additional information: There was an error reflecting type 'MyClass'.
Since MyClass
holds other class object as properties first I thought I have to make those serializabel too, however the exception still persists.
So, my guess is, that it is impossible serialize this
, however I couldn't find a confirmation to this guess.
EDIT: This property causes the issue according to the inner exception:
[XmlArray("VolumePresetList"), XmlArrayItem(typeof(LinearAxisColorPresetsModel), ElementName = "VolumePresetList")]
public ObservableCollection<LinearAxisColorPresetsModel> VolumePresetList { get; set; }