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 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 86k
  • Answers 86k
  • 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
  • Editorial Team
    Editorial Team added an answer I'd use a MultiScaleTileSource for that. It's a callback based… May 11, 2026 at 5:23 pm
  • Editorial Team
    Editorial Team added an answer I've used a turtorial on encosia.com to do just that.… May 11, 2026 at 5:23 pm
  • Editorial Team
    Editorial Team added an answer I think you definitely need to pop-up an Alert box… May 11, 2026 at 5:23 pm

Related Questions

Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.
When creating scrollable user controls with .NET and WinForms I have repeatedly encountered situations
I have a web-based application and a client, both written in Java. For what
This is a strange one... In a windows forms app (VB.NET/VS 2005) I have

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.