I'm getting this error when trying to serialize an object in C#
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
Additional information: There was an error reflecting type 'ComboGen.ElementLocation'.
What I'm trying to do is serialize all the control elements in a form so I can read them back in and repopulate the form.
My class that I want to serialize and holds the control elements is defined like
[System.Serializable]
[System.Xml.Serialization.XmlInclude(typeof(ElementLocation))]
public class ElementLocation
{
public List<ElementLocation> subElements;
public TextBox ActionName;
public TextBox CoolDown;
public TextBox ClearInputBuffer;
public Button AddCombo;
}
To serialize it I'm using
System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create(myStream);
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(ElementLocation));
foreach (ElementLocation elemLoc in elementLocations)
{
serializer.Serialize(xmlWriter, elemLoc);
}
myStream.Close();
But it throws an exception when trying to call Serialize. Can someone tell me what I'm doing wrong here?