Message: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

Hi everyone, I began the “Get Started With RPA Development” course. Here, the task was to build my first automation process in Studio.

Process Description: Build a process which downloads an Excel attachment from an email, extracts the data from the file and enters it into an online form.

I have followed the exact instructions that are provided in the video from the course. However, I have encountered this error message and have not been able to find the reason why nor how to fix it.

Please refer to the attachments above. Thank you and appreciate everyone’s helps.


Welcome to our UiPath community.

Get Outlook Mail Message activity didn’t retrieve any emails from Outlook here but you tried to save the attachments from first mail because of that you got this error.

Uncheck the mail you want to save attachments from it then try once.

Check MailMessages count before Saving Attachments.

        MailMessages.Count > 0
        Then - Save attachments and read file
         Else - No Email found


If you create your workflow as the video, can you try the following in advance?

First, create email which has subject named “New Task” and some attachment, then send it to yourself.
Outlook will receive it, then keep it as unread.
Finally, run your workflow in UiPath Studio.



Have you managed to resolve this issue?
I’m getting the same error message.
I tried Laksmans’ suggestion:
MailMessages.Count > 0
Then - Save attachments and read file
Else - No Email found
It’s not really helping because MailMessage.Count is bigger than zero.
The workflow is failing on SaveAttachment activity because MailMessages(0).Attachments(0) index is out of range. It seems the the process is not able to find attachment in the mail although the the file is attached.

Thank you,