ReSharper: how to remove "Possible 'System.NullReferenceException'" warning

Resharper only looks at the current method for its analysis, and does not recursively analyse other methods you call.

You can however direct Resharper a bit and give it meta-information about certain methods. It knows for example about "Assert.IsNotNull(a)", and will take that information into account for the analysis. It is possible to make an external annotations file for Resharper and give it extra information about a certain library to make its analysis better. Maybe this might offer a way to solve your problem.

More information can be found here.

An example showing how it's used for the library Microsoft.Contracts can be found here.


A new answer in old post...

Here a little sample of my code regarding how to use CodeContract via ContractAnnotation with Resharper:

    [ContractAnnotation("value:null=>true")]
    public static bool IsNullOrEmpty(this string value)
    {
        return string.IsNullOrEmpty(value);
    }

It is very simple...if u find the breadcrumb in the wood. You can check other cases too.

Have a nice day