There is a class in the code that contains a dictionary (Dictionary<key, value>) that would have intended the former to implement the Ideserializationcallback interface in order to initialize the contents of the dictionary when deserializing. The result loop dictionary element code is not to go. It took a lot of effort to find out why, first look at the problematic code:
Using System;
Using System.Collections.Generic;
Using System.IO;
Using System.Runtime.Serialization;
Using System.Runtime.Serialization.Formatters.Binary;
namespace Dotnetbugs {[Serializable] public class Example:ideserializationcallback {
Private dictionary<string, string> map = new dictionary<string, string> (); Public Example () {map.
ADD ("One", "1"); Map.
ADD ("Two", "2");
public void OnDeserialization (object sender) {Dump ();
public void Dump () {foreach (var item in map) { Console.WriteLine (item. Key + "->" + item.
Value); }} public class Starter {public static void Main (string[] Arg s) {
using (var stream = new MemoryStream ()) {var formatter = new Binaryf
Ormatter (); Formatter.
Serialize (Stream, New Example ()); Stream.
Seek (0, seekorigin.begin); var example = (example) formatter.
Deserialize (stream);
Console.WriteLine ("After Deserialize"); Example.
Dump ();
Console.read (); }
}
}
}
What kind of output do you expect the console to have?
One-> 1 |
Two-> 2 | When the 44th row is deserialized, the output of the dump is called in example.ondeserialization. After
deserialize one
-> 1 |
Two-> 2 | Call dump output on line 47th
But the actual output is:
After deserialize one
-> 1
two-> 2