Datatable has a value but throwing null reference


I have a task to use nested loop

In the second loop it is throwing the null reference exception but the datatable which i have used have rows and i have seen the row count and the particular row value in the message box

RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.
at UiPath.Core.Activities.ForEach`1.StartLoop(NativeActivityContext context)
at UiPath.Core.Activities.InterruptibleLoopBase.Execute(NativeActivityContext context)
at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

@yoichi @ppr



Can you share your workflow or expression?
The Row.Item might be null.


we recommend to debug and using the different debug panels instead of message boxes…
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

when debugging (e.g. stepwise) then you cn trace where the variable becomes null. Maybe some adjustments on the variable scope is needed

No, It has and Showing the values


Which activity or expression throws exception? Can you share it?


Please share your workflow details in order to help

For each row in datatable @Yoichi @ppr

The weird thing is on the above steps it shows the values and while stepped into the for it is showing null

The scope of the variable is assigned to the parent sequence


check and play with the variable scope especially when involved within a for each…

Now i have created a new variable for that filter , it is throwing this error @ppr

Source: For Each Row in Data Table

Message: Collection was modified; enumeration operation might not execute.

Exception Type: System.InvalidOperationException

RemoteException wrapping System.InvalidOperationException: Collection was modified; enumeration operation might not execute.
at System.Data.RBTree1.RBTreeEnumerator.MoveNext() at UiPath.Core.Activities.ForEach1.InternalExecute(NativeActivityContext context, IEnumerable values)
at UiPath.Core.Activities.ForEach`1.GetStateAndExecute(NativeActivityContext context, ActivityInstance completedInstance)
at System.Activities.Runtime.ActivityCompletionCallbackWrapper.Invoke(NativeActivityContext context, ActivityInstance completedInstance)
at System.Activities.Runtime.CompletionCallbackWrapper.CompletionWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

do not touch the looped collection e.g. removing, adding items

I haven’t changed anything

which things / actions are you doing within the failling for each row?

1 Like

Inside the for each i’m having another for each and inside that based on the condition the row.itemArray will be added in the datatable

looks like modifying the same datatable which is involved within the for each

1 Like

I’m using three different datatable

And I’m using the Clear datatable inside the For each :no_mouth: :man_facepalming: and that’s the problem.

Thank you @ppr @Yoichi @mosa_sleeman

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