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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:28:56+00:00 2026-05-28T21:28:56+00:00

I have been working on a system which I’m using protobuf-net (version 2.0.0.480) for

  • 0

I have been working on a system which I’m using protobuf-net (version 2.0.0.480) for serializing messages. This application uses a CQRS approach in which commands and events have been separated into different namespaces [and assemblies].

The code will dynamically add the types at runtime for any class that inherits from MessageBase. This is done using the code below:

    // Used as a unique reference for each type in a member
    private static int _sequence = 1000; 
    public static void RegisterAll()
    {
        RegisterAllDerivedFrom<MessageBase>();
    }
    public static void RegisterAllDerivedFrom<T>(params Assembly[] assemblies)
    {
        if (assemblies == null || assemblies.Length == 0)
        {
            assemblies = AppDomain.CurrentDomain.GetAssemblies();
        }

        var type = typeof(T);
        var model = RuntimeTypeModel.Default;
        var metaModel = model.Add(type, true);

        RegisterAllBaseTypes(type, metaModel, model, assemblies);
    }
    private static void RegisterAllBaseTypes(Type type, MetaType metaModel, RuntimeTypeModel model, params Assembly[] assemblies)
    {
        foreach (var t in assemblies.SelectMany(a => a.GetTypes().Where(t => t.BaseType != null && t.BaseType == type)))
        {
            var subModel = model.Add(t, true);
            metaModel.AddSubType(_sequence, t);
            _sequence++;

            RegisterAllBaseTypes(t, subModel, model, assemblies);
        }
    }

A few types are added manually to the Default RuntimeTypeModel as well:

RuntimeTypeModel.Default.Add(typeof(ReferenceNumber), true)
            .AddSubType(100, typeof(Product))
            .AddSubType(110, typeof(ProductGroup));

All the above seems to work fine when all messages were in:

LogicalGrouping.Events

The project moved forward and a new namespace was added:

ReferenceGrouping.Commands

Once ReferenceGrouping.Commands is added and attempts to send a message a ProtoException is thrown. The only workaround that I found for this behaviour is to add the Commands from ReferenceGrouping.Commands into LogicalGrouping.Events.

Is this the anticipated behaviour or should the RuntimeTypeModel be able to support classes being added from completely different namespaces?

  • 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-28T21:28:56+00:00Added an answer on May 28, 2026 at 9:28 pm

    Protobuf-net, as per my comment, simply does not care about namespaces, type names or member-names, since it uses numeric keys as identifiers (in accordance with the protobuf spec). This means you can deserialize on a completely different model in dfferent assemblies, as long as the numbers make sense.

    Looking at the code, I strongly suspect the problem is that you don’t have reliable (repeatable) sub-type identifiers. If you have, when serializing:

    • Foo
      • SubFoo1 (key=2)
      • SubFoo2 (key=5)

    Then it is vitally important, when configuring the models for deserialization, keys that are compatible; for example you could deserialize into:

    • Bar
      • MegaBar (key=2)
      • UltraBar (key=5)

    My guess is that your mechanism for adding sub-types is not ensuring the numbers match. It needs some clue. Actually, looking at your code I wonder if it could also break currently if:

    • adding types
    • removing types
    • renaming types
    • relocating types
    • just … Any time (the order of types is not guaranteed, IIRC)

    My advice would be: keep an external registration somewhere of what each key means in terms of sub-types. Or: do the same in code using ProtoIncludeAttribute.

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

Sidebar

Related Questions

I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been working on an app which includes using the devices camera. After
I have a Winforms application which is working fine.. using a BackgroundWorkerThread to manage
I have been working with a Linq query in a Silverlight application which returns
I have been working on this plugin system. I thought I passed design and
I'm new to AS3 and have been working on an XML driven navigation system
OK, I have been working on a random image selector and queue system (so
We have been using XMLRPC for android and it was working well until we
A system I have been working on for a while requires DPA, and asked
I have been working on Flash AS3 project. I am designing a 3D system.

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.