It's an odd problem; Response
(according to Reflector) is:
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public HttpResponse Response
{
get
{
if (this._response == null)
{
throw new HttpException(SR.GetString("Response_not_available"));
}
return this._response;
}
}
So it can't return null - you'd get an HttpException
instead.
Likewise, Cookies
is:
public HttpCookieCollection Cookies
{
get
{
if (this._cookies == null)
{
this._cookies = new HttpCookieCollection(this, false);
}
return this._cookies;
}
}
So you wouldn't get null there either.
The Cookies
' indexer? Nope:
public HttpCookie Get(string name)
{
HttpCookie cookie = (HttpCookie) base.BaseGet(name);
if ((cookie == null) && (this._response != null))
{
cookie = new HttpCookie(name);
this.AddCookie(cookie, true);
this._response.OnCookieAdd(cookie);
}
return cookie;
}
So I thought, the only thing we have left, is inside the Cookies
indexer, if this._response == null
, the cookie setting will not happen and this will return null
. But that can't happen either since _cookies
is only ever in that line we saw earlier, which calls a constructor which is the only place where _response
is set - set to the correct HttpRespones
, never null
.
In conclusion, I've dug deep in there and can't see any way for the Response.Cookies["haspassed?"].Expires
setter to ever throw a NullReferenceException
.