c# - HttpCookieCollection.Get(): Possible NullReferenceException -


i see resharper warning 'possible nullreferenceexception' on code on second line:

var cookie = httpcontext.current.response.cookies[cookiename]; cookie.expires = datetime.now.adddays(-1); 

i checked httpcookiecollection.get() method in msdn , says 'if named cookie not exist, method creates new cookie name.'. looks nullreferenceexception can't happen.

is resharper bug or missed something?

so looks nullreferenceexception can't happen.

httpcontext.current null if execute code outside of asp.net context, example unit test, console or desktop application.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -