Perhaps it isn't that thisValue
is Nothing
, it is the fact that .ToString()
is returning Nothing? Try this code to test it out:
Public Overridable Function Comparer(thisValue As Object, otherValue As Object) As Integer
Try
If thisValue Is Nothing Then
If otherValue Is Nothing Then
Return 0
Else
Return -1
End If
Else
If otherValue Is Nothing Then
Return 1
Else
Dim thisValueStr As String = thisValue.ToString()
Dim otherValueStr As String = otherValue.ToString()
'HERE, CHECK THE TWO STRINGS FOR NULL!!!
Return thisValueStr .CompareTo(otherValueStr )
End If
End If
Catch ex As Exception
Return 0
End Try
End Function
If this is the case, double-check the implementation of ToString()
in the object being passed (assuming it is a custom type).