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 6000523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:42:20+00:00 2026-05-23T00:42:20+00:00

Marc mentioned on stackoverflow that it will be possible in v2 of protobuf-net to

  • 0

Marc mentioned on stackoverflow that it will be possible in v2 of protobuf-net to use ProtoInclude attribute (or similar approach) to serialize/deserialize class hierarchy without a need to specify each subtype in the base class. Is this implemented yet? We have a plugin interface that can be derived in external libraries, so there is no way of knowing what the derived types will be. We could maintain unique numbering between types though, but I couldn’t find any examples on the net, short of using ProtoInclude attribute which requires a subtype to be specified.

How would I go about implementing inheritance with protobuf-net like that if I don’t know what the subtypes are?

  • 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-05-23T00:42:21+00:00Added an answer on May 23, 2026 at 12:42 am

    If you can’t specify the subtypes in attributes (because it isn’t known at compile-time) you have 2 options (both of which only apply to “v2”, available as beta):

    1. use a RuntimeTypeModel, rather than the static Serializer methods (which are now just a short-cut to RuntimeTypeModel.Default); tell the model about the inheritance (example below)
    2. add DynamicType = true to the [ProtoMember(...)] in question

    The second is not very pure protobuf – it embeds type information, which I don’t really love but people just kept asking for. The first is my preferred option. To add subtypes at runtime:

    var model = TypeModel.Create();
    var type = model.Add(typeof(YourBaseType), true);
    var subTypeA = model.Add(typeof(SomeSubType), true);
    var subTypeB = model.Add(typeof(SomeOtherSubType), true);
    type.AddSubType(4, typeof(SomeSubType));
    type.AddSubType(5, typeof(SomeOtherSubType));
    

    the true in the above means “use normal rules to add member properties automatically” – you can also take control of that and specify the properties (etc) manually if you prefer.

    Note that a TypeModel should be cached and re-used (not created per object you need to serialize), as it includes some “emit” code to generate methods. Re-using it will be faster and require less memory. The type-model is thread-safe, and can be used to serialize/deserialize multiple streams concurrently on different threads.

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

Sidebar

Related Questions

I'm using protobuf-net (thanks Marc :) ) to serialize my object model, but I
I have been trying to use protobuf-net with MonoTouch but I have no idea
I want to understand why the protocol buffers solution for .NET developed by Marc
I'm trying to replace an existing serializer with protobuf for C# by Marc Gravell.
I have just read about http://marc.info/?l=php-internals&m=131031747409271&w=2 . I use mysql_query in all my php
Many of you know, that there's is a class RealViewSwticher created by Marc Reichelt
I'm using Migrator.NET to write database migrations for the application. Marc-André Cournoyer wrote: Like
In this thread , Marc Bernier mentioned SWIG also generated a bunch of C#
I exchanged emails with Marc-André Cournoyer of RefactorMyCode.com about supporting Delphi on his site.
Update Thanks to Marc's help the AlphaPagedList class is now available on CodePlex if

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.