Home » Category » NET Architecture & Design

NET Architecture & Design: IDeserializationCallback called in wrong order?

205| Tue, 20 May 2008 08:57:00 GMT| anonymous| Comments (0)
Hi all, I have an issue with trying to do some sort of initialisation on
classes after deserialization.

I know that the IDeserializationCallback is specifically designed for this
purpose, but it seems to be called in the wrong (non-intuitive) order for
child objects.

e.g.
say I have two classes, ParentClass and ChildClass where ParentClass
contains a member instance of ChildClass, both classes implement the
ISerializable and IDeserializationCallback interfaces and both classes need
to do some sort of initialization after being deserialised.

Deserialization order seems to be :

ParentClass.ParentClass(SerializationInfo info, StreamingContext c);
ChildClass.ChildClass(SerializationInfo info, StreamingContext c);
ParentClass.OnDeserialization(object sender);
ChildClass.OnDeserialization(object sender);

Now I would have expected that the order should be:

ParentClass.ParentClass(SerializationInfo info, StreamingContext c);
ChildClass.ChildClass(SerializationInfo info, StreamingContext c);
ChildClass.OnDeserialization(object sender);
ParentClass.OnDeserialization(object sender);

because the ParentClass has not really completed deserialization (hence
should not call OnDeserialization(object sender)) until all of its members
are fully deserialized.

My problem is that the initialization of ParentClass
(ParentClass.OnDeserialization(object sender)) depends on the ChildClass
having been initialized and obviously this has not yet happend.

I could expose the ChildClass's "Initialise()" function and have the
ParentClass call this in its OnDeserialization(object sender) but this just
seems to be an inelegant hack, surely there is a better way?

Eamon

Keywords & Tags: ideserializationcallback, called, wrong, order, net, architecture, design

URL: http://dotnet.itags.org/dotnet-architecture-design/153008/
 
«« Prev - Next »» 0 helpful answers below.

NET Architecture & Design Hot Answers

NET Architecture & Design New questions

NET Architecture & Design Related Categories