Hi
I need help for one of my first robots. I use invoke code with c# as selected language, and get an Invoke Code: Exception has been thrown by the target of an invocation.
My code looks like this:
`OpgaverTilSletning=new DataTable();
OpgaverTilSletning.Columns.Add("OpgaveID");
OpgaverTilSletning.Columns.Add("Refnr");
foreach (DataRow row in AlleOpgaver.Rows)
{
string refnr = row["Refnr"].ToString();
// Find den matchende række i den anden DataTable
DataRow[] matchingRows = AnalyseOpgaver.Select("Refnr = '" + refnr + "'");
if (matchingRows.Length > 0)
{
// Tilføj rækken til 'OpgaverTilSletning'
OpgaverTilSletning.Rows.Add(row);
}
}`
Thanks. I get this error:
RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.ArgumentException: This row already belongs to another table.
at System.Data.DataTable.InsertRow(DataRow row, Int64 proposedID, Int32 pos, Boolean fireEvent) at UiPath.CodeRunner.UiPathCodeRunner_1daa47548f074073bdb8bb410292e83d.Run(DataTable AnalyseOpgaver, DataTable AlleOpgaver, DataTable& OpgaverTilSletning)
— End of inner exception stack trace —
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) at UiPath.Activities.System.Utilities.InvokeCode.CompilerRunner.Run(Object[] args) at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode, List1 inArgs, IEnumerable`1 imps, Object args) at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
I tried to modify line 14 to this:
OpgaverTilSletning.Rows.Add(row.Copy());
But that is not the solution.
Then i tried to add types to the columns but that didn’t make any diference too.
The error message shows Column “OpgaveID” and/or “Refnr” already exists in the datatable.
So can you check it? If you already added them outside invokeCode, please remove these lines.
Or, add If statement to check if the above column exists, then add it when it doesn’t exist.