Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:46:18+00:00 2026-06-04T17:46:18+00:00

I have two classes A and B. Class B inherits class A as shown

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:46:19+00:00Added an answer on June 4, 2026 at 5:46 pm

    In the ProtoAttributes for A, you need to specify that it can also contain B.

    <ProtoContract(), ProtoInclude(100, GetType(B))>
    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(1)>
        Property Title As String = String.Empty
        <ProtoMember(2)>
        Property Status As String = String.Empty
    End Class
    

    And this is the test class I used to figure yours out.

    Public Class Test
        Public Sub New()
            Dim stuff As New B With {.ID = 1, .Name = "Bob", .Title = "Director", 
                 .Status = "Active"}
    
            Dim buffer As Byte()
            Using memStream As New IO.MemoryStream
                ProtoBuf.Serializer.Serialize(memStream, stuff)
                buffer = memStream.ToArray
            End Using
    
            Dim deserializedStuff As B
            Using memStream As New MemoryStream(buffer)
                memStream.Position = 0
                deserializedStuff = ProtoBuf.Serializer.Deserialize(Of B)(memStream)
            End Using
    
            Debug.Print(deserializedStuff.ID.ToString & "--" & deserializedStuff.Status)
        End Sub
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes class A { public string something { get; set; }
I have two classes: public class DocumentViewModel { public virtual string DocumentNumber { get;
I have the following two classes, one inherits from the other Class A{ void
I have two classes: public class CourseModule { // attributes... List<Course> courses; public void
my code is like this: i have two classes first class: public class Box<E>
I have a problem with hibernate and criterias. I have two Classes: public class
I have the two classes: public class PartDefinition { public int Id { get;
I have these two classes public class Person { } public class Company {
I have two classes, WebServiceRequest and OrderRequest. Each class has properties. OrderRequest inherits from
I have two classes in python Drunk Usual Drunk The usual drunk class inherits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.