"possible null assignment to entity marked NotNull attribute" warning on HttpUtility.HtmlEncode

139 views Asked by At

Using Resharper 7.1.3, Visual Studio 2012, .net 4:

This code:

    string str = null;
    str = System.Web.HttpUtility.HtmlEncode(str); 

Generates the warning : "possible null assignment to entity marked NotNull attribute". But when I looked at the code for HttpUtility.HtmlEncode using Reflector, it looks like the code ends up checking for a null string, and gets out straight away in such cases. Is this one of those cases where Resharper (?) has got it wrong ? Or is a check such as :

if (str != null)
   str = System.Web.HttpUtility.HtmlEncode(str);   

really necessary ?

0

There are 0 answers