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

I began with the “Get Started With RPA Development” course. In the 1st video tutorial I encounter the "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index.

Please see the attached screenshot. I am using the MailMessages(0) index as indicated in the tutorial. Any assistance, will be greatly appreciated.

Thanks!
workbookreadrange

Out of range error comes when the array is empty .

As your screenshot MailMessages(0) - here MailMessages is empty so it is not able to get the first items means index(0).

First check for empty and try to print the count of elements in MailMessages

in message box give MailMessages.count.

try to handle it with try catch block

Hi @hectorpe ,

In Such scenarios always try to put if condition before saving any attachment on index value.

If (MailMessages.Count>0) then save attachment else throw exception.

I had the same error when I went through the tutorial. In the get mail messages activity, there are two checkboxes. One for “MarkAsRead” and one for “OnlyUnreadMessages”.

You get this error on subsequent attempts to run the automation because the bot marked your message as read on the first attempt. Either manually mark your message as unread or uncheck the “OnlyUnreadMessages” box and you should be good to go.

2 Likes

When you say two checkboxes, Where do I find them ?

Go to your mail that you have sent it to yourself and mark it as Unread. Then the program will be executed.

Or you go to get latest task outlook me and in properties
check MarkAsRead
uncheck onlyunreadmessages

Even I am facing the same issue but when uncheck the onlyunreadmessages and ran did not worked. Please suggest me as what i need to do

So, Guys All You have to do is that: While you Send the mail to your account put the Subject name as “New Task” (Not in these commas, Okay!) That’s It!
Simple Solution, Reply to me If You get the Output!

Reason:
While taking the First Activity of " Get Data " i.e: GetOutlookMailsMessages, there we had typed
“[Subject] = ‘New Task’” in property tab, → Option Category, → Filter. So, Our Automation will only run when we fulfill the given condition. Or Simpler Way when we follow the above-mentioned Condition.
Thankyou, Have a Nice Day!

i have tried that Solution with and without commas , Still i am facing the Same issue , Looking forward for your help :pray:

any update cause am also find same issue
but maybe cause of our email has alot of emails>>> and in that videos only one email was in the index