I found the error. When something like that occurs it means one element can't be processed. To find out which one I had to look at the inner exception where the element's name is shown. With that name in hand I added it as an element to ignore
Original code:
Public Function Serialize(Of T)(ByVal ObjectToSerialize As T) _
As String
Dim xmlSerializer As XmlSerializer =_
New XmlSerializer(ObjectToSerialize.[GetType]())
Using textWriter As StringWriter = New StringWriter()
xmlSerializer.Serialize(textWriter, ObjectToSerialize)
Return textWriter.ToString()
End Using
End Function
And after the change where the element ExtensionData1 is ignored
Public Function Serialize(Of T)(ByVal ObjectToSerialize As T) As String
Dim xOver As XmlAttributeOverrides = New XmlAttributeOverrides
Dim attrs As XmlAttributes = New XmlAttributes
attrs = New XmlAttributes
attrs.XmlIgnore = True
xOver.Add(ObjectToSerialize.[GetType](), "ExtensionData1", attrs)
Dim xmlSerializer As XmlSerializer = New XmlSerializer(ObjectToSerialize.[GetType](), xOver)
Using textWriter As StringWriter = New StringWriter()
xmlSerializer.Serialize(textWriter, ObjectToSerialize)
Return textWriter.ToString()
End Using
End Function