Serialization and duplicate references to same object?

Serialization and duplicate references to same object?

Old forum URL: forums.lhotka.net/forums/t/5232.aspx


rsbaker0 posted on Tuesday, August 12, 2008

Let's say I have an object that happens to contain two references to the same contained object (e.g. object.ReferenceEquals(obj1, obj2) will return true).

Now I serialize this object across the data portal and it is deserialized on the application server.

Do I get two copies of the contained object, or is the framework actually smart enough to reproduce the original situation with two references to one copy of the object?

skagen00 replied on Tuesday, August 12, 2008

I'm not 100% sure about the answer but I'm going to guess it's smart enough to give you two references to the one copy.

That's an interesting question though.

RockfordLhotka replied on Tuesday, August 12, 2008

The BinaryFormatter and NetDataContractSerializer both preserve the shape of the object graph. So they are smart enough to handle this.

Be aware that n-level undo is not that smart though, so you could end up with some really odd edit level scenarios if you aren't careful.

stefan replied on Wednesday, August 13, 2008

Well,
I still had in mind that in such a situation we had to mark each redundant reference as <NonSerialized()>,
and reset the reference in an OnDeserialized override to avoid trouble...

I know that with the current version of Csla, we no longer need to rehook events in the OnDeserialized override. Now is this also true for resetting reference duplicates?

Rocky, could you please state what version of Csla came with that changed behaviour?
The original post was version unspecific...

Stefan

RockfordLhotka replied on Wednesday, August 13, 2008

CSLA 3.5 introduced the field manager, which is what allows CSLA to automatically manage child events.

 

Marking the duplicate child reference as NonSerialized is not a bad idea, because it probably reduces the size of the serialized byte stream. But you will need to reestablish the child reference yourself in OnDeserialized.

 

Rocky

Copyright (c) Marimer LLC