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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:54:35+00:00 2026-05-21T10:54:35+00:00

Given the following classes, public static void Test() { var bigDictionary = new Dictionary<string,

  • 0

Given the following classes,

public static void Test()
{
  var bigDictionary = new Dictionary<string, TestClass>();
  bigDictionary.Add("entry1", new TestClass());
  bigDictionary.Add("entry2", new TestClass());
  bigDictionary.Add("entry3", new TestClass());

  // EDIT: Added these lines
  bigDictionary["entry1"].MyDictionary.Add(1, new SecondTestClass() { MyVar = "hello" });
  bigDictionary["entry1"].MyDictionary.Add(2, new SecondTestClass() { MyVar = "world" });
  bigDictionary["entry2"].MyDictionary.Add(1, new SecondTestClass() { MyVar = "please" });
  bigDictionary["entry2"].MyDictionary.Add(2, new SecondTestClass() { MyVar = "work" });

  using (var file = System.IO.File.Create("test.temp"))
  {
    ProtoBuf.Serializer.Serialize(file, bigDictionary);
  }

  Dictionary<string, TestClass> outDict = null;
  using (var file = System.IO.File.OpenRead("test.temp"))
  {
    outDict = ProtoBuf.Serializer.Deserialize<Dictionary<string, TestClass>>(file);
  }

  // EDIT: You'll notice these asserts fail
  System.Diagnostics.Debug.Assert(outDict["entry1"].MyDictionary.ContainsKey(1));
  System.Diagnostics.Debug.Assert(outDict["entry1"].MyDictionary.ContainsKey(2));
  System.Diagnostics.Debug.Assert(outDict["entry2"].MyDictionary.ContainsKey(1));
  System.Diagnostics.Debug.Assert(outDict["entry2"].MyDictionary.ContainsKey(2));

}

[System.Runtime.Serialization.DataContract]
public class TestClass
{
  public TestClass()
  {
    MyDictionary = new Dictionary<int,SecondTestClass>();
  }

  [System.Runtime.Serialization.DataMember]
  public Dictionary<int, SecondTestClass> MyDictionary { get; set; }
}

[System.Runtime.Serialization.DataContract]
public class SecondTestClass
{
  [System.Runtime.Serialization.DataMember]
  public string MyVar { get; set; }
}

(How) can I get bigDictionary to serialize without throwing the following exception?

"Only data-contract classes (and lists/arrays of such) can be processed (error processing Dictionary`2)"

(I have tried tagging with DataContract/DataMember ProtoContract/ProtoMember etc. but nothing seems to work)

Thanks in advance for any help.

EDIT: Seems I have kinda worked it out. Given the above edited code, you’ll notice the asserts fail. So it would seem that the inner dictionary is not being serialized at all. However, if I change the DataContract tags to Protobuf.ProtoContract (and DataMember to ProtoMember), it correctly picks up the inner dictionary.

Am I mis-using the library or is this a bug?

  • 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-21T10:54:36+00:00Added an answer on May 21, 2026 at 10:54 am

    The answer is that the exception being thrown was a little misleading, it was a serialization error of an object in the dictionary not the dictionary itself. The actual implementation I was dealing with was a little more complex than the example I gave, and as such had a variable of type object which was breaking it.

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

Sidebar

Related Questions

Given the following two classes: public class ABC { public void Accept(Ordering<User> xyz) {
Given the following: public abstract class Base { // other stuff public static void
Given the following classes and controller action method: public School { public Int32 ID
Given the following domain classes: class Post { SortedSet tags static hasMany = [tags:
Given the following classes: public class Container { private List<SomeData> list; // public getter
Given the following XML structure <html> <body> <div> <span>Test: Text2</span> </div> <div> <span>Test: Text3</span>
Consider the following code: public abstract class Base { public void getAnswer(); } public
I have the following classes. public class B { public A a; public B()
Given following Ruby statements: (Read input and store each word in array removing spaces
Given the following XML: <current> <login_name>jd</login_name> </current> <people> <person> <first>John</first> <last>Doe</last> <login_name>jd</login_name> </preson> <person>

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.