views:

9

answers:

0

As MSDN states here, it can. But I've spent 2 hours digging mscorlib code, because in some cases the BinaryFormatter called my method marked with OnDeserialized BEFORE deserialization constructor. That is, the order was

OnDeserializing(StreamingContext context)
OnDeserialized(StreamingContext context)
.ctor(SerializationInfo info, StreamingContext context)

While I was expecting it to be

OnDeserializing(StreamingContext context)
.ctor(SerializationInfo info, StreamingContext context)
OnDeserialized(StreamingContext context)

And the final point. When I implemented IDeserializationCallback interface, its method OnDeserialization was called AFTER constructor, as I wanted and expected.

I tried to reproduce this on some simple class structure, but there everything worked fine. In our project the objects graph being serialized is very complex, so I do not know where to dig. Inspecting the mscorlib code with reflector did not help a lot - the deserialization code is too complicated for me to figure out where the problem comes from.

So, does anybody know what could be causing such problem? We use the assumption that OnDeserialized is called BEFORE the constructor in several other places so I am scared now that it is not very reliable...

Thanks!