I have object A and object B deserialized from binary files. B has a private method which is used as a callback function and does some manipulation on a private data member when A raise an event. To clarify the basic structure:
Class A
{
private static A instance;
public static A GetInstance(){...};
private A(){}
public delegate void SomeCallback(Arg a);
public event SomeCallback doCallback;
...
}
Class B
{
private Dictionary<., .> dict;
public B()
{
A.GetInstance().doCallback += new A.SomeCallback(ManipulateDict);
...
}
private void ManipulateDict(Arg a){...} //breakpoint here
public void PrintDict(){...}
}
After A and B is deserialized, whenever A raise event doCallback, I can see the breakpoint line(ManipulateDict) will be executed as I'm expecting. However, the strange thing is, it will manipulate on a 'dict' which has a different memory address with the object's, which means, even if ManipulateDict 'successfully' updated some data in dict, the other methods, say, PrintDict, still don't see the changes in dict.
If I don't use serialization, this won't happen and it behaves just right. But as serialization is introduced to this program, things goes weird. Am I doing something wrong? Who can explain this?
Thank you very much!