Source: For Each Message: Object reference not set to an instance of an object. \

Iam receiving the error like this

Source: For Each

Message: Object reference not set to an instance of an object.

Exception Type: System.NullReferenceException

RemoteException wrapping System.NullReferenceException: Object reference not set to an instance of an object.

@abrarsyed612

Before ForEach loop, use Message Box and print below value and check it whether its printing any value or not.

                                mails.Count
1 Like

I think mails is Null. Please run in debug mode and see what is the value for mails.

2 Likes

@SowmyaLeo
This is the Screen shot of debug mode.

It seems that value for mails is null, So what should I do now.

@lakshman
This is the error it seems so what should I do now, I must create a variable ah?

image

@abrarsyed612

From the debug mode I see “messages” (the next variable after mails ) holding the list of mail messages.

In your ForEach please use that variable instead of mails.

If mails is what you intend to use: mails should be of type List (System.Net.Mail.MailMessages). The output from the activity above it (the get mail mesage activity) should be assigned to mails.

1 Like

@abrarsyed612

May I know in what type of variable did you saved output of Get Outlook Mail Message activity ?

Is it System.Collections.Generic.List<System.Net.Mail.MailMessage> or not ?

System.Collections.Generic.List<System.Net.Mail.MailMessage>

Yes,Iam using this variable only.

@lakshman
System.Collections.Generic.List<System.Net.Mail.MailMessage>

Yes,Iam using this variable only

1 Like

@abrarsyed612

Then mails.count should work if mails is of type List. Could you please show me screenshot of mails variable type ?

@lakshman

@abrarsyed612

I think you should be using for each item in messages. Please give that a try. mails is of type Ienumerable in your case.

1 Like

@abrarsyed612

You need to store Get Outlook Mail Messages activity output in messages variable but not mails.

1 Like

System.Collections.Generic.List<System.Net.Mail.MailMessage>
If I use this I am getting the error like this.

@lakshman
I can’t understand what ur saying.

@lakshman @SowmyaLeo

I want to reply to unread messages from my outlook.

so tell me the solution for that.

@abrarsyed612

Do one thing. Delete all variables and go to output section under properties of Get Outlook Mail Message and press Ctrl+k and enter name like mailMessages and then check it.

1 Like