none
Outlook 2007 PIA reference RRS feed

  • Question

  • This is my first time using Office PIAs, and have run into a problem when using my app on a different machine.

    I have a console app that uses Outlook PIAs. Everything works fine on my development box, but when I move it to my staging machine, I get the following error: "Object reference not set to an instance of an object". I have Outlook 2007 installed my my staging machine, along with the Office 2007 PIAs. I have verified that Microsoft.Office.Interop.Outlook exists in the GAC.

    The reference on my project for Microsoft.Office.Interop.Outlook points to C:\Program Files (x86)\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11\Microsoft.Office.Interop.Outlook.dll. I have even tried creating this path on my staging machine, still with no luck.

    Am I referencing the outlook PIA wrong? I added the reference from the .NET tab.


    Michael Ruberg - www.landofsharepoint.com
    Monday, March 22, 2010 7:44 PM

Answers

  • Ok, apparently casting to object wasn't the solution. I just thought it was becuase it started working when I did so. I did one thing different at the same time when it started working though which i didn't think would matter: I had Outlook opened.

    So, you cannot just have Outlook installed along with the PIAs, it actually must be open and running...no idea why but it does.


    Michael Ruberg - www.landofsharepoint.com
    Tuesday, March 23, 2010 9:12 PM

All replies

  • The message means that your code has done something to create an instance of an object, and then you're not checking that the object actually exists and referencing it somehow, maybe calling a method.  So the short answer is that your code doesn't have any diagnostics or checks for errors, so it crashes when something isn't perfect. This is just normal debugging - find out where it failed, find out what object didn't get created, and then there may be enough information to see what's wrong. 
    Phil Wilson
    Monday, March 22, 2010 9:38 PM
  • I guess I should explain more. The object that is trying to be used is the Microsoft.Office.Interop.Outlook PIA. it is referenced in my project and Outlook 2007 is installed on my dev machine. On the staging machine, Outlook 2007 is also installed, along with the Ofice 2007 PIAs. The problem is that the compiled app does not work on the staging machine because it cannot find the Microsoft.Office.Interop.Outlook DLL, even though it is showing up in the GAC on the staging machine, and everything is installed. Am I using or referencing the PIA wrong?
    Michael Ruberg - www.landofsharepoint.com
    Monday, March 22, 2010 11:27 PM
  • Hi Michael,

    Based on the error message, I would suspect that the cause would be related to the different environment of the two machine.

    Could you please try the following two points?

    Point 1:

    To obtain the reference to interop with Outlook in your program, we should install the PIA of the Outlook (first install Outlook).

    Please follow the steps to add the reference:

    - Delete PIA references from your project
    - Right click the references > Add Reference... > COM tab
    - Select "Outlook 12.0 Object Library" to add its PIA into your project

    Point 2:

    Set the property "Copy Local" of PIA reference to true. This determines whether a reference is copied to the local bin path.
    For more detail information, please check: http://msdn.microsoft.com/en-us/library/t1zz5y8c.aspx

    Hope this helps! If you have any concern, please feel free to let me know.

    Best regards,
    Yichun Chen
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, March 23, 2010 10:13 AM
  • Ok, figured it out. I had to cast the SaveAs type to an object as shown below, which is where the error was occuring.

    _Application outlookApp = new ApplicationClass();
    _MailItem msg = (_MailItem)outlookApp.CreateItem(OlItemType.olMailItem);
    
    // code to create the message
    
    msg.SaveAs(result, (object)Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSG);

     

    I still have no idea why this would have worked on one machine but not the other. And the error "Object reference not set to an instance of an object" makes no sense for this type of error either. Oh well...it is working now.


    Michael Ruberg - www.landofsharepoint.com

    Tuesday, March 23, 2010 4:28 PM
  • Ok, apparently casting to object wasn't the solution. I just thought it was becuase it started working when I did so. I did one thing different at the same time when it started working though which i didn't think would matter: I had Outlook opened.

    So, you cannot just have Outlook installed along with the PIAs, it actually must be open and running...no idea why but it does.


    Michael Ruberg - www.landofsharepoint.com
    Tuesday, March 23, 2010 9:12 PM
  • Hi Michael,

    Thank you for your kindly sharing!

    I'm so glad to hear this good news.

    Have a nice day.

    Best regards,
    Yichun Chen
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, March 24, 2010 2:51 AM