:wave:
So I have the following classes:
I then built a List(of ControlTypeBase) and tried to serialize it using the following code:
However, the code errors on the Serializer.Serialize line saying "There was an error generating the XML document." That isn't very helpful, so I burrow down to the InnerException and it says "{"The type ConBlastUi.TextBoxType was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."}"
I tried adding the XmlInclude and SoapInclude attributes to the TextBoxType class (not at the same time), but still the same error.
So what am I missing here?
So I have the following classes:
Code:
Public Class ControlTypeBase
Private m_ControlName As String
Public Property ControlName() As String
Get
Return m_ControlName
End Get
Set(ByVal value As String)
m_ControlName = value
End Set
End Property
End Class
Public Class TextBoxType
Inherits ControlTypeBase
Private m_Text As String
Public Property Text() As String
Get
Return m_Text
End Get
Set(ByVal value As String)
m_Text = value
End Set
End Property
End Class
Public Class ComboBoxType
Inherits ControlTypeBase
Private m_SelectedValue As Object
Private m_SelectedIndex As Integer
Public Property SelectedValue() As Object
Get
Return m_SelectedValue
End Get
Set(ByVal value As Object)
m_SelectedValue = value
End Set
End Property
Public Property SelectedIndex() As Integer
Get
Return m_SelectedIndex
End Get
Set(ByVal value As Integer)
m_SelectedIndex = value
End Set
End Property
End ClassCode:
Public Shared Sub SerializeList(ByVal ThingToSerialize As List(Of ControlTypeBase), ByVal DestinationPath As String)
Dim Writer As New IO.StreamWriter(DestinationPath)
Dim Serializer As New Xml.Serialization.XmlSerializer(ThingToSerialize.GetType)
Serializer.Serialize(Writer, ThingToSerialize)
Writer.Close()
End SubI tried adding the XmlInclude and SoapInclude attributes to the TextBoxType class (not at the same time), but still the same error.
So what am I missing here?