You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The description of TryCast says that it will not throw an exception, and this error only appears on the line where I am trying to assign the result to a string. String does implement IEnumerable(Of Char).
Below is not a complete implementation of this routine just enough to show the warning and several cases without the warning.
Function IsEmpty(Of T)(ByVal lSource As IEnumerable(Of T)) As Boolean
Dim readOnlyCollection As IReadOnlyCollection(Of T) = TryCast(lSource, IReadOnlyCollection(Of T))
If readOnlyCollection IsNot Nothing Then
Return readOnlyCollection.Count = 0
End If
Dim genericCollection As ICollection(Of T) = TryCast(lSource, ICollection(Of T))
If genericCollection IsNot Nothing Then
Return genericCollection.Count = 0
End If
Dim collection As ICollection = TryCast(lSource, ICollection)
If collection IsNot Nothing Then
Return collection.Count = 0
End If
' The following line gets Warning on iSource
Dim str As String = TryCast(**lSource**, String)
If str IsNot Nothing Then
Return str.Length = 0
End If
Return True
End Function
With the code above there should be no warnings Expected Behavior:
No Warnings Actual Behavior:
Warning BC42322 Runtime errors might occur when converting 'IEnumerable(Of T)' to 'String'.
The text was updated successfully, but these errors were encountered:
Version Used:
Vs 2017 15.5.2
Steps to Reproduce:
Below is not a complete implementation of this routine just enough to show the warning and several cases without the warning.
Expected Behavior:
No Warnings
Actual Behavior:
Warning BC42322 Runtime errors might occur when converting 'IEnumerable(Of T)' to 'String'.
The text was updated successfully, but these errors were encountered: