I seem to be having an issue deserializing a CookieContainer. It serializes fine, but when I deserialize I am getting the error Object reference not set to an instance of an object
at this line below cookieJar = (CookieContainer)info.GetValue("cookieJar", cookieJar.GetType());
.
But if I uncomment the line that creates a new cookie container, I don't get the error, and the serialized CookieContainer is deserialized.
The cookieJar property is a property of MySession class.
public MySession(SerializationInfo info, StreamingContext context)
{
//cookieJar = new CookieContainer()
cookieJar = (CookieContainer)info.GetValue("cookieJar", cookieJar.GetType());
email = info.GetString("email");
password = info.GetString("password");
client = new HttpClient(new HttpClientHandler() { CookieContainer = cookieJar });
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("cookieJar", cookieJar);
info.AddValue("email", email);
info.AddValue("password", password);
}
Why is this?