timmkrause
timmkrause

Reputation: 3621

ReSharper help: Possible NullReferenceException

ReSharper says "Check if 'UserHostAddress' is not null" when I'm accessing HttpContext.Current.Request.UserHostAddress (it is in a try/catch block).

Within another method get the following property from the request object:

HttpContext.Current.Request.RawUrl

How does ReSharper determine or "know" that Request cannot be null? Or Current? Or HttpContext?

Maybe it is a bad example with this framework object chain but I think you get the point.

Upvotes: 1

Views: 257

Answers (1)

ulrichb
ulrichb

Reputation: 20044

R# uses its included External Annotations to provide these code annotations for types within the .NET Framework (like your mentioned ASP.NET classes).

The reason, why Jetbrains annotated for example HttpContext.Current as nullable is that in an console application (an application without HTTP context) HttpContext.Current returns null.

Upvotes: 3

Related Questions