none
outlook addin c#.net office interop error RRS feed

  • Question

  • Hello, 

    I am new to outlook addin development with c#.net,

    I need to test it with outlook 2010, 2013, 2007 (32 & 64bit)

    I made changes, that works with all version except 2010 64bit version of outlook.

    I got following error.

    System.Runtime.InteropServices.COMException (0x8004010F): The attempted operation failed.  An object could not be found.
       at Microsoft.Office.Interop.Outlook.Attachments.Add(Object Source, Object Type, Object Position, Object DisplayName)
       at myOutlookAddIn.ThisAddIn.ReportMsg(MailItem mailItem)


    Brijesh Vaidya India

    Thursday, January 23, 2014 4:48 PM

All replies

  • What is the relevant snippet of your code? Are you passing a fully qualified file name to Attachments.Add?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, January 23, 2014 4:55 PM
  • Hello Brijesh,

    Did you try to debug? What line of code fires the exception?

    > Microsoft.Office.Interop.Outlook.Attachments.Add(Object Source, Object Type, Object Position, Object DisplayName)

    What parameters do you pass to the Add method?

    Also please make sure that the Outlook item and Attachments object are still alive and were not released.


    Thursday, January 23, 2014 4:56 PM
  • Thank you for your reply,

    I passed the whole mailItem to Attachments.Add as follows:

     newMailItem.Attachments.Add( mailItem );

    -It is worked for 2007 and 2013 64bit version of outlook,

    I got this error only in 2010 64bit.


    Brijesh Vaidya India

    Friday, January 24, 2014 9:46 AM
  • I tried to debug on 32bit outlook 2010, my development environment with vs2010.

    in that  i did not get any error, also in 2007, 2013 32bit and 64bit outlook & 2010 32bit outlook with this addin.


    Brijesh Vaidya India

    Friday, January 24, 2014 11:09 AM
  • Hello Brijesh,

    I'd recommend breaking the chain of calls into separate lines and specify the attachment type parameter at least:

    Outlook.Attachments atts = mail.Attachments;
    Outlook.Attachment att = atts.Add(mailItemToAttach, Outlook.OlAttachmentType.olEmbeddeditem, Type.Missing, Type.Missing);
    The Add method of the Attachments class accepts four parameters. Did you try to specify all of them explicitly?
    Friday, January 24, 2014 11:35 AM
  • Hi Brijesh,

    Debug doesn't mean going through the code in the step-by-step manner. You can use the Debug.WriteLine method for printing debug messages to the console. There is no need to have Visual Studio installed on the problematic machine. However, you can attach the debugger to the problematic machine and debug the code remotely.

    Anyway, the Add method of the Attachments class accepts four parameters. Did you try to specify all of them explicitly?

    I'd recommend specify the second parameter explicitly - OlAttachmentType.

    Friday, January 24, 2014 11:39 AM
  • Where does mailItem come from? Is the message saved?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, January 24, 2014 1:26 PM
  • Thank you for your reply, 

    I checked the code, and only one argument that is, the object source is passed and it is the MailItem, the object of the interface Microsoft.Office.Interop.Outlook.MailItem.

    Other arguments are optional.


    Brijesh Vaidya India

    Friday, January 24, 2014 2:11 PM
  • Yes,

    I can use

    Debug.WriteLine(" Object is not valid for this category.");

    or

       MessageBox.Show("in the method");

    I can also try this, thank you.


    Brijesh Vaidya India

    Friday, January 24, 2014 2:18 PM
  • I am aware that other parameters are optional. Instead, I'd suggest specifying them explicitly. At least, I'd recommend to specify the second argument - OlAttachmentType.
    Friday, January 24, 2014 2:56 PM
  • Of course, the MessageBox class can be used too. But it blocks the execution thread until you close it.

    Anyway, please let me know your results.

    Friday, January 24, 2014 2:58 PM
  • thank you for reply,

    the mailItem came from the addin itself.

    I am not saving the message on drive, I only fetch the attachment detail and mail body detail and then send this information to the sender, then  I resend the message to sender email address.

    this error comes only in outlook 2010 64bit version,

    all other version of outlook 2010 32bit, 2007, 2013-32bit & 64bit, it works fine.


    Brijesh Vaidya India

    Friday, January 24, 2014 5:21 PM