This project has moved and is read-only. For the latest updates, please go here.

ImportConstructor in class that is being serialized/deserialized

May 13, 2013 at 8:21 PM
I incorporated MEF into a desktop application in which I serialize and deserialize the object. I use the ISerializable interface to control my binary serialization. During regular object instantiation the objects constructor is called in which it has an ImportingConstructor. How do you get MEF imports when the object is being created during deserializations using
MyObject(SerializationInfo info, StreamingContext context)?
May 13, 2013 at 9:52 PM
You could switch to property imports and fix them up post-deserialization, but I'd be concerned about the fragility of mixing parts and serialization this way. As a rule of thumb, things with a 'persistent identity' make poor parts- MEF really wants to be in control of which instance is used where.

In this situation I usually try to separate the serialized and non-serialized data into different (related) classes. This might work for you..?

Good luck!
May 15, 2013 at 3:17 AM
Thank you for the advice