This project has moved. For the latest updates, please go here.

ImportConstructor in class that is being serialized/deserialized

May 13, 2013 at 7: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 8: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 2:17 AM
Thank you for the advice