0

I have a deep object hierarchy where the base class parameterless constructor looks like this:

public class BaseClass 
{
    private Session session_;
    public BaseClass()
    {
        session_ = ...;
    }
}

Serialization is OK. Problem happens in deserialization when the object construction tries to establish a connection to a webservice to construct the session object which is not necessary at all as all the values obtained from the session have been serialized. So the question is how do I customize / override the constructor to skip the deserialization of session field?

Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
  • ^ In summary: Either write an explicit constructor for JSON.net to use, or implement your own (de)serialization logic – Rob Apr 11 '16 at 11:46
  • Or you can use `FormatterServices.GetSafeUninitializedObject` as is described in [How to deserialize class without calling a constructor?](https://stackoverflow.com/questions/13947997/how-to-deserialize-class-without-calling-a-constructor). – dbc Apr 11 '16 at 23:37

0 Answers0