This false positive is only reported, when using an OrElse-Condition in a Null-Check an using the checked variable in a For-Each-Statement. Please see following example:
Visual BasicPublic Class Class1
Public Function Foo() As Integer
Dim list As String() = Nothing
If (list Is Nothing) OrElse (list.Count = 0) Then
list = {"Item"}
End If
'CRR0027 (false positive)
For Each listItem As String In list
'Do something
Next
'No CRR0027
Return list.Count
End Function
Public Function Bar() As Integer
Dim list As String() = Nothing
If (list Is Nothing) Then
list = {"Item"}
ElseIf (list.Count = 0) Then
list = {"Item"}
End If
'No CRR0027
For Each listItem As String In list
'Do something
Next
'No CRR0027
Return list.Count
End Function
End Class
Hi Robert,
Thank you for providing the code sample. I have reproduced this issue with the "Possible System.NullReferenceException" diagnostic false positive. We are working on it and will notify you on our progress.