Why "Index was outside the bounds of the array" error?

I want to initialize an array and store data, but I don’t wanna specify the length. I thought dynamic array existed, but why am I getting an error: Index was outside the bounds of the array?

I have out argument out_myArray of type string. I then used Assign activity.

Assign: out_myArray = new string(){} /* Making it dynamic */
Assign: out_myArray(0) = “Test1”

this second line already gives an error! I am so confused. If I change the first line to:

Assign: out_myArray = new string(5){} /* Just assigned any length */

this works! Why do I have to specify the length for array declaration? I am so at a loss.


In general Array is meant to be of fixed size and VB.Net is no. exception.

If you want a dynamic list of string then you can simple use List of String.

You can add remove new items whenever you need.

Have a thought.

1 Like

Thank you but I would still like to know why, then, dynamic array is even a thing. And if there is any way to make this happen on UiPath

1 Like

I am not sure if you can achieve what you described. But you can resize the array by using ReDim and if you want to preserve the data in the array while resizing use ReDim Preserve.

Use Invoke code activity to execute the ReDim statement and assign output back to your original array.
DynamicArray.xaml (4.8 KB)

This post may also be relevant. How to initialize an Three-Dimensional Array String [] [] []?


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