NET Architecture & Design: IDeserializationCallback called in wrong order?

  • anonymous / 205 / Sun, 05 Apr 2009 11:29:00 GMT / 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:

    ideserializationcallback, called, wrong, order, net, architecture, design

  • http://dotnet.itags.org/dotnet-architecture-design/153008/«« Last Thread - Next Thread »»