I have a simple property inside one of my ASP.NET MVC Controller classes.

I’ve seen this many times before, so understand what the message means, but usually it makes perfect sense. This, however, doesn’t. To get to the underlined statement, User would have to NOT be null, so the check for User.Identity is fine.
The Identity property is part of the IPrincipal interface, and returns an object that inherits IIdentity.
To inherit this interface, or any interface for that matter, this property must be a reference type, and therefore can potentially be null, right?
So why is my beloved ReSharper moaning?
You said you are using the
GenericPrincipleas the implementation ofIPrincipal. For this class, theIdentityproperty can indeed never benull. It is easy to see if you look at the source code (e.g. using JetBrains dotPeek).You can thank ReSharper’s code annotations for the .NET framework class libraries for this.
In my ReSharper 6.1 annotations, there is this single code annotation related to this (in file ExternalAnnotations\mscorlib\mscorlib.4.0.0.0.Nullness.Generated.xml):
This is just for the constructor though, I haven’t found one for the
Identityproperty. So either you are using a ReSharper version that has annotation for that property too or ReSharper is doing some additional analysis.In any case, it is ReSharper being clever (and right!).