2

Some background about my problem: I have a lot of classes that implement ISerializable and are designed to be serialized using the explicit BinaryFormatter methods: .ctor(SerializationInfo info, StreamingContext context) and void GetObjectData(SerializationInfo info, StreamingContext context) I have recently discovered that BinaryFormatter does not always call the constructor when deserializing an object. Supposedly, the BinaryFormatter is supposed to be copying the object graph bit-for-bit into memory, and so doesn't call the constructor on the 'Already Constructed' object. This is not working for me: My private members are always null references when OnDeserialized is called and the constructor had not run. This could potentially be resolved if I could still retrieve the serialized data collected by GetObjectData, but I cannot find anything but the constructor that gives me access to the SerializationInfo object.

My question, then: Is there any way, other than .ctor(SerializationInfo info, StreamingContext context), to retrieve the values that were collected during void GetObjectData(SerializationInfo info, StreamingContext context)?

Or: Any clue how the BinaryFormatter decides whether to call the constructor or not? If I could just force the BinaryFormatter to always use the constructor, I believe my problem would be solved.

Nathan
  • 1,675
  • 17
  • 25
  • I have abandoned the `BinaryFormatter` in favor of `XmlSerializer`. It required a bit of effort to get our code entities switched over, but at least it's consistently calling `ReadXML()`. – Nathan Jan 26 '12 at 17:37

0 Answers0