Resharper is showing a "Possible System.NullReferenceException" warning. I however can't see how I can get one.
public class PlaceController : PlanningControllerBase
{
[Authorize]
public ActionResult StartStop(int id)
{
if (Request != null && Request.Cookies != null && Request.Cookies["place"] != null)
{
if (Request.Cookies["place"].Value != null)//Possible NullReferenceException?
{
string placeInformation = Request.Cookies["place"].Value;//Possible NullReferenceException?
//...
}
}
}
}
How can this give a NullReference if I check all fields? Using the following doesn't show the warning:
Request.Cookies[0];//Index instead of name
Edit: updated code.
I assume the checker isn't checking the value of the string passed to the CookieCollection indexer is the same each time. I imagine if you restructure the code to:
if (Request != null && Request.Cookies != null)
{
var place = Request.Cookies["place"];
if (place != null && place.Value == null)
{
string placeInformation = place.Value;
}
}
It might work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With