I have class A, which exposes an event. an object of class B subscribed to the event. Both instances actually also hold a regular reference to eachother. I'd like to serialize A, and have both objects be transferred over the wire, to be reconstructed at the other end. This works fine, except that the event subscription is not retained.
I think I have to implement my own serialization constructor in order to 'be notified' when my objects gets deserialized, so it can resubscribe to the event.
However, it looks like that means I have to completely implement seialization myself by implementing ISerializable. I now rely on BinaryFormatter, and [Serializable] attributes, and actually like that very much.
Does anybody know a way for me to get notified on deserialization, while still being able to use the built in serialization system to automatically serialize & deserialize my somewhat complex object graph for me?
Thanks, Lucas
The standard (non-XML) serialization mechanism uses special attributes to mark methods to be used as callbacks during (de)serialization . OnDeserializedAttribute is what you're looking for. Similar solution is implementing IDeserializationCallback interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With