Possible NullReferenceException

Hi!
I have a function that returns an instance of a class. This function never returns null. However if I get the return value from this function and try to use it later resharper gives a 'Possible NullReferenceException'. It seems that I need to declare somewhere that my function never returns null so that resharper knows.
How do I do that?

1 comment

Assuming you're using R# 4.x, you can add the JetBrains.Annotations.NotNullAttribute to your function and this warning should go away. To get this attribute, you can either add a reference to JetBrains.Annotations.dll to your project, or by copying and pasting the attribute declarations into your assembly (use the "Copy default implementation to clipboard" button on the Code Annotations page of the R# options dialog to do the copy part).

For more information on this and the other annotations available, look at the documentation (under Code Analysis for for C# > External Annotations) or this page: http://www.jetbrains.com/resharper/features/code_analysis.html#Annotated_Framework.

Hope this helps,
..David..

0

Please sign in to leave a comment.