0

I am attempting to pass a cookie to an API to consume one of its services. However, it comes up with this error, so matter how I attempt to do so. Here is the line of code where this occurs:

_service.CookieContainer.Add(new Cookie("ASP.NET_SessionId", sessionID) { Domain = "webservices.24sevenoffice.com" });

Does anyone know how to resolve this issue? SessionID is NOT null, and the other values are explicitly given so it's quite confusing.

J.J.
  • 1,087
  • 2
  • 17
  • 53
  • 1
    The only things in that line that looks like they could be `null` and causing that error are `_service` or `CookieContainer` - are they definitely set to something? Assuming that the error is thrown _by that specific line_ and not within the `Add` method or `Cookie` constructor. – James Thorpe Jun 10 '15 at 14:45
  • Either way, the techniques described in the answers to [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) should help you track down the issue. – James Thorpe Jun 10 '15 at 14:45
  • _service must be defined like _service = new ...(); before this line because you are trying to add cookieContainer to service. this is the only possible thing i can see from here depending on your error. – M.kazem Akhgary Jun 10 '15 at 14:49
  • if there is List of CookieContainer inside service you must set List inside constructor too. like `List CookieContainer= new List`inside Constructor.how ever i dont know what is the type of _service – M.kazem Akhgary Jun 10 '15 at 15:00

0 Answers0