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

  • SEARCH
  • Home
  • 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 8623147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:12:58+00:00 2026-06-12T07:12:58+00:00

Given a .proto that looks like this: message Base { string Dummy = 1

  • 0

Given a .proto that looks like this:

message Base {
    string Dummy = 1
}

message Derived {
    Base Super = 1
    string Parp = 2 
}

… And some C# something like:

public class Base {
    public string Dummy;
}

public class Derived : Base {
    public string Parp
}

How would one go about customising the serialisation in protobuf-net to be able to do this? Initially I started looking at using a TypeModel and calling AddSubType for the Base MetaType, but then it seems it creates type definitions for Base with optional fields of all the derived classes (ie the other way around vs what I require)

I thought I might be able to walk the hierarchy myself but looking at TypeModel, it seems to support supplying the type to Deserialise but it uses value.GetType() during serialisation. Even then it wasn’t entirely clear how I might do this. Is my only option to use ProtoWriter to write every field by hand? This is what I am currently attempting, but I hoped there was an easier way.

  • 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-12T07:12:59+00:00Added an answer on June 12, 2026 at 7:12 am

    The first thing to note is that protobuf itself does not support inheritance. There is no “official” layout for this. Protobuf-net will not support serialization the way you desire: the choice of sub-type encapsulation (rather than base-type encapsulation) was made to fix several issues, including:

    • satisfying the Liskov substitution principle
    • working correctly when the serialized type was not known/expected by the caller
    • basically, working at all (for anything other than the simplest example where both ends know in advance exactly which sub-type they are getting, which largely defeats the point of polymorphism)

    However, you could map the DTO manually, basically so your DTO layer doesn’t use inheritance at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some jQuery with an Ajax call that looks like this: $.ajax({ type:
Given that the web application doesn't have su privileges, I'd like to execute a
I have a pretty common case for nested routes, I feel like, that looks
Given the sample code: class Base { public: bool pub; protected: bool prot; };
Given this method to work on a HTML page in a webbrowser: bool semaphoreForDocCompletedEvent;
given a Python class hierarchy, say class Base: def method1 def method2 def method3
Given a MySQL table of real estate data, I would like to generate a
Let me preface this by saying that my code seems to work for all
Given a database with records like the following Table: AuditLog Fields: ID | USERID
I'm trying to make a grammar in Boost.Proto that matches a vector type, but

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.