DataContractSerializer doesn’t call my constructor?

DataContractSerializer (like BinaryFormatter) doesn’t use any constructor. It creates the object as empty memory.

For example:

    Type type = typeof(Customer);
    object obj = System.Runtime.Serialization.
        FormatterServices.GetUninitializedObject(type);

The assumption is that the deserialization process (or callbacks if necessary) will fully initialize it.

Leave a Comment