Invoke Code:Exception has been thrown by target of invocation

Hi Guys
“Invoke Code:Exception has been thrown by target of invocation” ,this exception has been raised while getting the subject body and attachment from an email using invoke code activity

Can Someone help me here

Dim outlook As _Application = New Microsoft.Office.Interop.Outlook.Application()
Dim item As MailItem = CType(outlook.CreateItemFromTemplate(in_MsgFile,Type.Missing),MailItem)
Dim ListOfAttachments As New List(Of String)

Dim Count As Integer
Count= item.Attachments.Count
For i As Integer = 1 To Count
Next i


This is the code which i have written

1 Like

Exception has been thrown by target of invocation - error occurs if the value goes null to the variable.

Check for any null values assigned/passed.

Check the values assigned to the argument.

1 Like

I have checked them…no null values is passed.
Is there anything else i should check…Cause i have done this for another case where i got the result perfectly. Actually what i am doing is that in a folder i have multiple outlook items i should download all the attachments from the items to the same folder itself. This exception is raised only for one specific case. I have done the same case successfully for another folder containing multiple outlook items

Thank you…it is solved. What you have said is correct ,a null value was passed to the variable.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.