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.

1 Like

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.

12 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.

2 Likes

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

1 Like

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!

1 Like

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

1 Like

I was having the same problem and I found the solution. When typing “[Subject] = ‘New Task’” I had a space between the k and the ’ it looked like this: “[Subject] = 'New Task '”
It was subtle but that extra space makes all the difference.

I finally solve this error by adding my email account in the Properties tab on the Input section. Hope this works for most of you.

2 Likes

Has anyone responded? I am having the same issue

@madlim how did you add the email account in the Expression Editor (window)? None of the above mentioned solutions are working for me.

In the first activity Get Data i.e. GetOutlookMailMessages, Go to the Properties tab > Input > Account, add your account in the expression editor “xyz@uipath.com

Solved, this works for me. thanks!

This worked for me. Thank you so much!

Thanks @Ajay_Mishra it worked for me.

Hi everyone,

I need some help, I’m still figuring out how to fix this. I’m stuck on the same issue, I’ve tried all of the possible solutions that was mentioned here but it didn’t worked for me. :frowning: