Trying to automate Outlook as
Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office
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!
//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;
Same error exactly in the same place:
Outlook.NameSpace ns = application.GetNamespace("MAPI");
I have a Win 10 and Office 365 - both 64 bits - with no previous Office installation; I tried several solutions above and did too Office quick repair, to no avail.
After running a Office online repair it functions like a charm.
For me removing 9.5 entry from this registry works:
HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046}
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.
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.