Outlook Interop Exception

1

Trying to automate Outlook as

Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();    
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");

and getting following exception at second line i.e. GetNamespace

Unable to cast COM object of type 'Microsoft.Office.Interop.Outlook.ApplicationClass' to interface type 'Microsoft.Office.Interop.Outlook._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063001-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

I am using .Net Framework 4 and Outlook 2013.

Is this the only solution!!! as I am trying to avoid making any changes to the registry.

Edit

this didn't fix the problem.

Edit If the referenced library is Office 15 and the installed library is 10 or 12, would it work?

c#
com
outlook
office-interop
com-interop
asked on Stack Overflow Aug 22, 2013 by bjan • edited May 23, 2017 by Community

9 Answers

2

I've been stumped by this problem for days. This worked for me:

I just realized that Outlook 2013 is 64 bit... And my C# app had in Project Properties -> Build "Any CPU" as platform target and a check-mark in "Prefer 32-bit".

I changed the Platform target to x64 and it worked!

answered on Stack Overflow Aug 31, 2016 by (unknown user)
1

The exception looks quite obvious, this should work

    var myApp = new Microsoft.Office.Interop.Outlook.Application();

you just can't get a cast exception with that line above.

answered on Stack Overflow Aug 23, 2013 by Machinegon
1

This exception usually happens when you had two versions of Office installed and then uninstalled one. Run a repair installation for your still installed Office, this should fix the registry keys.

answered on Stack Overflow Sep 4, 2013 by cremor
0

have you tried this?

Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
answered on Stack Overflow Aug 22, 2013 by sevdalone
0

The fix of the 9.5 version didn't work for me, as there was no excessive 9.5 field.

In my case, the problem was that when I downgraded to Outlook 2010 I have modified the installation location (i.e. not in the default ProgramFiles folder). However, windows didn’t update accordingly the value in ‘HKEY_CLASSES_ROOT\TypeLib{00062FFF-0000-0000-C000-000000000046}\9.4\0\win64’.

After manually updating the value and pointing it to the right location, the problem was resolved.

answered on Stack Overflow Feb 14, 2015 by Doigen
0

I ran into the exact same error message you have, my problem was I had installed Office 2016 x64 while the app that was trying to call into it was compiled as x86. Switching to x86 Office 2016 solved the issue for me.

answered on Stack Overflow Jan 5, 2016 by Roger Perkins
0

I had this problem too. I use Mobisynapse desktop app to update my Android Calendar and contacts. Using Office 2010 I decided to upgrade to Office 2016. After seeing it was a Office 365 product I uninstalled it. This caused the Registry to change the Office 2010 Primary Interop Assemblies to change from 32 bit to 64 bit. The Mobisynapse MB4Outlook started reporting sync error "Sync Failed". Mobisynapse – Moffice error 3/31/19 Sync Failed – there is a problem with outlook – on the desktop When I click on Auto Sync settings I get “Please update MB4Outlook add-in first” From where it is installed with your app.

Solution to this problem occurs when you try an Office365 product that is 64bit and have a 32 bit of office 2007-2013 installed. Step 1: uninstall Office xxxx primary interop assemblies. If the package is not found download from here. https://www.microsoft.com/en-US/Download/confirmation.aspx?id=3508 Install it. Step 2: run Office xxxx Install and select repair. Step 3: Reboot and it should fix the problem.

answered on Stack Overflow Mar 31, 2019 by user4206575
-1
   //DECLARE
    Microsoft.Office.Interop.Outlook.Application app = null;
    Microsoft.Office.Interop.Outlook.NameSpace ns = null;

  //INITIALISE
    app = new Microsoft.Office.Interop.Outlook.Application();
    ns = app.Session;
answered on Stack Overflow Dec 17, 2014 by TheDanMan
-1

For me removing 9.5 entry from this registry works:

HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046}

answered on Stack Overflow Jul 14, 2017 by Atmaram • edited Jul 14, 2017 by Columbia says Reinstate Monica

User contributions licensed under CC BY-SA 3.0