System.InvalidOperationException: There was an error generating the XML document.

Error:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Windows.Media.MatrixTransform was not expected. Use the XmlInclude attribute to specify types that are not known statically.
Above error occurs when you try to serialize an object to XML.
Reason:You are trying to serialize a class / type that is not serializable.
Ho do you solove it: Simple. Ignore the non serializable object before you try to serialize the object to XML
Use [XmlIgnore] attribute on the property;
e.g:

[XmlIgnore]
public SolidColorBrush MyForeground { get; set; }
XmlIgnore comes under the following class
System.Xml.Serialization

Comments