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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:15:39+00:00 2026-05-24T05:15:39+00:00

(NOTE: Dictionary where T is some ProtoContract / ProtoMembered class works fine. ) This

  • 0

(NOTE: Dictionary where T is some ProtoContract / ProtoMembered class works fine. ) This issue only happened for me with type object.

I was trying to serialize a dictionary of Dictionary working.

typeof(object) doesn’t work. Should it? Should I implement a string based work around?

In this scenario, object will only ever be a .net primitive.

    [Test]
    public void De_SerializeObjectDictionary2()
    {
        var d = new Dictionary<string, object>();

        d.Add("abc", 12);

        var ms = new MemoryStream();

        var model = ProtoBuf.Meta.RuntimeTypeModel.Default;
        //model.AutoAddMissingTypes = true;
        //model.AutoCompile = true;
        //model.InferTagFromNameDefault = true;
        //model.Add(typeof (object), false);
        //model.Add(typeof(Int32), true);
        //model[typeof (object)].AddSubType(50, typeof (Int32));

        model.Serialize(ms, d);
        Serializer.Serialize<Dictionary<string,object>>(ms, d);
        // <--- No serializer defined for type: System.Object

        // or
        //model.Add(typeof (object), false);
        //Serializer.Serialize<Dictionary<string, object>>(ms, d);
        //<-- Unexpected sub-type: System.Int32
        ms.Position = 0;

        var d2 = Serializer.Deserialize<Dictionary<string, object>>(ms);
    }

I attempted to define these types ahead of time… but I think they’re handled by default by protobuf-net

        //model.Add(typeof (object), false);
        //model[typeof (object)].AddSubType(50, typeof (Int32));
        /*
        //model.Add(typeof(int), false);
        //model.Add(typeof(string), false);
        //model.Add(typeof(short), false);
        //model.Add(typeof(DateTime), false);
        //model.Add(typeof(long), false);
        //model.Add(typeof(bool), false);
        //model.Add(typeof(int[]), false);
        //model.Add(typeof(string[]), false);
        //model.Add(typeof(short[]), false);
        //model.Add(typeof(DateTime[]), false);
        //model.Add(typeof(long[]), false);
        //model.Add(typeof(bool[]), false);

        //model.Add(typeof(int?), false);
        //model.Add(typeof(short?), false);
        //model.Add(typeof(DateTime?), false);
        //model.Add(typeof(long?), false);
        //model.Add(typeof(bool?), false);
        //model.Add(typeof(int?[]), false);
        //model.Add(typeof(short?[]), false);
        //model.Add(typeof(DateTime?[]), false);
        //model.Add(typeof(long?[]), false);
        //model.Add(typeof(bool?[]), false);

        //model.Add(typeof(byte[]), false);
        //model.Add(typeof(byte), false);
  • 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-24T05:15:39+00:00Added an answer on May 24, 2026 at 5:15 am

    The desire to do this directly has already been proposed, and is on my list to look at, but: treating types with inbuilt serialisation (int etc) as part of inheritance has some technical issues that are not very interesting. My recommendation here is to use an abstract base class with generic concrete implementation, and an “include” attribute on the base-type to cite each of the expected types at runtime – Foo<int>, Foo<string> etc. DynamicType would also be a consideration here, but without a few minor tweaks I don’t think this works immediately for dictionary. It could do, though.

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

Sidebar

Related Questions

I'm very new to multi-threading and for some reason this class is giving me
(Note: This is an extension of a previous question .) I am having some
Note: This was posted when I was starting out C#. With 2014 knowledge, I
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
Note : The code in this question is part of deSleeper if you want
Note The question below was asked in 2008 about some code from 2003. As
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
Note This is not a REBOL-specific question. You can answer it in any language.
I have the following code: public static class ScraperMasterUriDetails { public static Dictionary<Guid, string>
(NOTE: I've updated this question from the initial inquiry about child containers towards creating

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.