I have two classes A and B. Class B inherits class A as shown below.
<ProtoContract()>
Public Class A
<ProtoMember(1)>
Public Property ID As Integer
<ProtoMember(2)>
Public Property Name() As String = String.Empty
End Class
<ProtoContract()>
Public Class B
Inherits A
<ProtoMember(101)>
Property Title As String = String.Empty
<ProtoMember(102)>
Property Status As String = String.Empty
<ProtoMember(103)>
End Class
When I use ProtoBuf to serialize and deserialize an instance of class B, the class A property values are lost. After searching for a bit on this, I think I need to use the ProtoInclude() tag on Class B somehow but I have had little luck with it.
Example Code:
Dim stuff as New B
With stuff
.ID = 1
.Name = "Bob"
.Title = "Director"
.Status = "Active"
End With
Dim buffer as Byte()
Dim deserializedStuff as new B
Using memStream As New IO.MemoryStream
ProtoBuf.Serializer.Serialize(memStream, stuff)
buffer = memStream.ToArray
End Using
Using memStream As New MemoryStream(buffer)
memStream.Position = 0
deserializedStuff = ProtoBuf.Serializer.Deserialize(Of B)(memStream)
End Using
At this point, the inherited property values on "deserializedStuff" are lost. They appear to just be set to their default values. Any ideas on what I am doing wrong? Thanks in advance.