C# – Outlook Interop Exception

ccomcom-interopoffice-interopoutlook

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?

Best Answer

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!

Related Topic