I'm having problems serializing an object & can't find a way around it.
I have 2 classes
Public Class SessionBase
Private _testString As String
Public Property TestString() As String
Get
Return _testString
End Get
Set(ByVal Value As String)
_testString = Value
End Set
End Property
End Class
-------- And -------------------
Public Class Session
Inherits SessionBase
Private _primaryResultset As Object
Public Property PrimaryResultset() As Object
Get
Return _primaryResultset
End Get
Set(ByVal Value As Object)
_primaryResultset = Value
End Set
End Property
End Class
-----------------------------------------------
I have a method that serializes instances of the base class
Private Function SerializeSessionBase(ByVal session As SessionBase) As String
Dim sw As New StringWriter
Dim xs As New XmlSerializer(GetType(SessionBase))
xs.Serialize(sw, session)
Return sw.ToString
End Function
------------------------------------------------------
& into this i'm passing an instance of Session.
I get the "The type Comtec.Applications.ThomasCook22.WWW.Session was not
expected. Use the XmlInclude or SoapInclude attribute to specify types that
are not known statically." error & i know i can fix it by using
<System.Xml.Serialization.XmlInclude(GetType(Sessi on))>
On the base class but if i do that the derived class gets serialized so i have
<SessionBase xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Session">
<TestString>b</TestString>
<PrimaryResultset xsi:type="xsd:string">a</PrimaryResultset>
</SessionBase>
Whereas what i want is just the properties from BaseClass, i.e. something like
<SessionBase xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Whatever">
<TestString>b</TestString>
</SessionBase>
Anyone got any ideas?