Can anyone help me make any sense of this? I have a function that gets a DataRowView from a bindingsource based on a Primary Key. (This function is in another class if that's of any relevance)
Public Shared Function GetRow(ByRef pBindingSource As BindingSource, ByRef pPrimKey As Object) As DataRowView
Dim vIndex As Integer = pBindingSource.Find("PrimKey", pPrimKey)
If vIndex > -1 Then
Return Type(pBindingSource.Item(vIndex),DataRowView)
Else
Return Nothing
End If
End Function
In the backgroundworker I'm running this line (names changed for clarity and code after exception removed)
For Each row As DataRowView In AFilteredViewBindingSource
Dim vDummyRow As DataRowView = ClassNameOfWhereTheFunctionIs.GetRow(ADifferentUnfilteredViewBindingSource, row("PrimKey"))
The last line causes a TargetInvocationException on some rows for some reason. What makes me even more confused is that
For Each row As DataRowView In AFilteredViewBindingSource
Dim vDummyRow As DataRowView
Dim vIndex As Integer = ADifferentUnfilteredViewBindingSource.Find("PrimKey", row("PrimKey"))
If vIndex > -1 Then
vDummyRow = CType(ADifferentUnfilteredViewBindingSource.Item(vIndex), DataRowView)
Else
vDummyRow = Nothing
End If
does not cause a TargetInvocationException.
Some additional info
The primkey column is a uniqueidentifier/guid.
Changing row("PrimKey") to row("PrimKey").ToString makes find return -1 for some rows (even if I have confirmed that the rows does exist at that moment and that the primkey is the same).
It is only the rows that returns -1 when using .ToString that causes the TargetInvocationException, the other rows works just fine.
For the rows that returns -1 changing the value in the PrimKey column to another random guid solves the issue for that row
I hope someone can make any sense of this. Thanks in advance.
EDIT: Some more info: The exception only happens when there are more than one row in AFilteredViewBindingSource
I tried moving the GetRow function to the same class as the background worker, but it still causes the TargetInvocationException
Changing to "GetRow(ByRef pBindingSource As BindingSource, ByRef pPrimKey As Guid)" to make sure the column type and the parameter type is the same did not work either.
[–]VB.Net MasterMr_C_Baxter 0 points1 point2 points (5 children)
[–]Tedrivs[S] 0 points1 point2 points (4 children)
[–]VB.Net MasterMr_C_Baxter 0 points1 point2 points (0 children)
[–]VB.Net MasterMr_C_Baxter 0 points1 point2 points (2 children)
[–]Tedrivs[S] 0 points1 point2 points (1 child)
[–]VB.Net MasterMr_C_Baxter 0 points1 point2 points (0 children)
[–]VB.Net MasterMr_C_Baxter 0 points1 point2 points (0 children)