For Each: Unable to cast object of type “System. Char” to type “System.Net.Mail.MailMessage”

Hi everyone,

I’ve started learning RPA a week ago, and I’m stuck.
I was supposed to create a sequence to automate the retrieval of email attachments from Outlook, and first, I kept getting an error (For Each: Unable to cast object of type “System. Char” to type “System.Net.Mail.MailMessage”). Please refer to my screenshot.
My Studio Page

The UiPath video- Building the Workflow—Part One

I noticed I do not have the same layout and function as the example in the video (Please refer to my Studio version).

Thank you in advance for your help,


Basically it’s necessary to set not string but list or array type variable at List of items.


Hi @Kate-Ketsirin ,

You should put the CourseEmails in the list of items and RetrievedEmail in the item field. Just interchange them, and don’t use double quotes.


Place a variable like Array or List type in the For each.
And the variable should not be in the double quotes(" ").

@Yoichi @Karthik_Reddy_A Thank you all for your advice. I took your advice, and it works!!!

Another error after Debugging,

I am working in non-tech related background, and I am new to UiPath. I do appreciate all your help and time.

@Kate-Ketsirin , can you manually verify if the excel contains the sheet named invoices?

The error is raised as the mentioned sheet is not found in the excel


Thank you for your swift reply. I’ve reviewed the Read cell value I put “E8” and the Excel file contains “E8”. What do you think?

@Kate-Ketsirin , please check the sheet name in which the data is present.

Regards, Got it! Misspelling for invoices- invoice. It works now.
I am encountering another error.

Thank you so much for your help.

1 Like

@Kate-Ketsirin , change the type of the variable in the read cell output to generic.


Followed your advice. I put “Generic” in the output, but it still does not work.

@Kate-Ketsirin ,

I was referring to the type:





@Kate-Ketsirin , the variable type is list of mail message in the screenshot, you have to make it as generic type. refer to my previous screenshot


The variable type dropdown does not have “Generic” Once I tried to search by clicking the “Brown for type” it pops up another error. Please refer to my screenshots.