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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:05:35+00:00 2026-05-11T02:05:35+00:00

I encountered a, at least to my expectations, strange behavior in the binary serialization

  • 0

I encountered a, at least to my expectations, strange behavior in the binary serialization of .NET.

All items of a Dictionary that are loaded are added to their parent AFTER the OnDeserialization callback. In contrast List does the other way. This can be really annoying in real world repository code, for example when you need to add some delegates to dictionary items. Please check the example code and watch the asserts.

Is it normal behaviour?

[Serializable] public class Data : IDeserializationCallback {     public List<string> List { get; set; }      public Dictionary<string, string> Dictionary { get; set; }      public Data()     {         Dictionary = new Dictionary<string, string> { { 'hello', 'hello' }, { 'CU', 'CU' } };         List = new List<string> { 'hello', 'CU' };     }      public static Data Load(string filename)     {         using (Stream stream = File.OpenRead(filename))         {             Data result = (Data)new BinaryFormatter().Deserialize(stream);             TestsLengthsOfDataStructures(result);              return result;         }     }      public void Save(string fileName)     {         using (Stream stream = File.Create(fileName))         {             new BinaryFormatter().Serialize(stream, this);         }     }      public void OnDeserialization(object sender)     {         TestsLengthsOfDataStructures(this);     }      private static void TestsLengthsOfDataStructures(Data data)     {         Debug.Assert(data.List.Count == 2, 'List');         Debug.Assert(data.Dictionary.Count == 2, 'Dictionary');     } } 
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T02:05:36+00:00Added an answer on May 11, 2026 at 2:05 am

    I can reproduce the problem. Had a look around Google and found this: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94265 although I’m not sure it’s the exact same problem, it seems pretty similar.

    EDIT:

    I think that adding this code may have fixed the problem?

        public void OnDeserialization(object sender)     {             this.Dictionary.OnDeserialization(sender);     } 

    No time to exhaustively test, and I want to beat Marc to the answer 😉

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

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer From documentation: Note that the table does not remain in… May 11, 2026 at 12:10 pm
  • added an answer I actually pulled my Petzold (2nd Edition) from the shelf… May 11, 2026 at 12:10 pm
  • added an answer All you have to do is create a new instance… May 11, 2026 at 12:09 pm

Related Questions

I encountered a, at least to my expectations, strange behavior in the binary serialization
I'm a bit flabbergasted at this, so I'm wondering if any SOers have encountered
I encountered a problem when running some old code that was handed down to
I encountered a strange problem today. Whenever i put a breakpoint in one of
I am developing my stuff in python. In this process I encountered a situation
I recently encountered a problem where a value was null if accessed with Request.Form
I've encountered a problem when retrieving a JSONP response from a server in a
I have encountered a rather odd error that I do not understand. I created
I've encountered a problem with my Netbeans 6.1 IDE. After an unsuccessful update, Netbeans
I have encountered a problem that I have not come accross yet when setting

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.