Invoke code returns Exception has been thrown by the target of an invocation

Hi All, I wanted to run some code in an Invoke code activity, but I always get an exception message which is: Exception has been thrown by the target of an invocation.

Here are the screenshots

And the code Im trying to run is:

' Use LINQ to set the background color of all rows to red '
dtLegajos1.AsEnumerable().ToList().ForEach(Sub(row) row.SetField(Of Object)("BackColor", "Red"))

' Create a new DataTable and copy the rows from the original table '
newTable  = dtLegajos1.Clone()
For Each row As DataRow In dtLegajos1.Rows

Any help on this is greatly appreciated, thank you, or if there is another solution I would also appreciate it

Hey @Sidney_Vogel ,

Try using this.

For Each row As DataRow In dt.Rows
    For Each col As DataColumn In dt.Columns
        row(col.ColumnName).BackColor = Color.Red


1 Like


Can you check content of $exceptionDetails in Locals panel when error occurs, as the following? There is detailed information for the exception.


Hi @Sidney_Vogel ,

Instead of this newTable = dtLegajos1.Clone() use below code

Dim newTable As DataTable = dtLegajos1.Copy()

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.