R#6.1: CanBeNullAttribute is back on System.Type.FullName

I was happy with R#6.0 since it did not define "System.Type.FullName" with CanBeNullAttribute.

To be clearer, I have a lot of code like this:

void MyMethod ( [NotNull] string typeName )

{

}


static void main ()

{

    Type type = typeof(MyType);

    MyMethod(type.FullName);

}


After installing R#6.1 I now get a lot of warnings with R# saying that the above call to MyMethod() can receive i null-reference to parameter typeName which is annotated with that [NotNull].

I known the documentation of System.Type.FullName say that it can return null in some cases, but those cases (as far as I understand it) will never occur when using the type as produced with a concrete type with the typeof-operator as shown in the above sample. I guess the R# team has been aware of this issue since the same code did not produce that warning in the latest R#6.0 but I remember it did in some earlier version (R#5.1, or maybe early R#6.0?).

I can see why the R# team concluded the way they did with R#6.1, but is there a way I can configure it as if System.Type.FullName is annotated with [NotNull], or - probably better - with no annotation at all? I have looked into the xml-files in "ReSharper\v6.1\Bin\ExternalAnnotations\System" but did find any definition for System.Type.FullName.

1 comment
Comment actions Permalink

Hello,

At this point, we can't differentiate cases of inferring System.Type - that's why we display a "worst-case" warning. By the way, have you tried to play with NullRef analysis options in
R# ->Options->CodeInspections->Settings-> Assume entity value can be null ?

Regards.

Kirill Falk
.NET Team QA Lead

0

Please sign in to leave a comment.