I'm trying to make a program that would open new Outlook 2007 message.
I've referenced from COM tab Microsoft Outlook 12.0 ObjectLibrary.
These items showed up in references in VS:
Microsoft.Office.Core
Microsoft.Office.Inerop.Outlook
Now I try to invoke following code:
var _outlookInstance = new Microsoft.Office.Interop.Outlook.Application();
var _message = (OutlookApp.MailItem)_outlookInstance.CreateItem(OutlookApp.OlItemType.olMailItem);
where OutlookApp==Microsoft.Office.Interop.Outlook namespace.
While invoking second line of listing I keep getting this exception: (InvalidCastException)
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: Library unregistered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
That code worked well for Outlook 2003 on my other station.
I'll be grateful for any ideas how to solve it.
Office is not properly installed on that machine. You can verify that with Regedit.exe, navigate to
HKEY_CLASSES_ROOT\Interface\{00063001-0000-0000-C000-000000000046}\TypeLib
to verify the type library GUID (should be {00062FFF-0000-0000-C000-000000000046}), then toHKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046}
to verify that the type library is indeed properly registered, using the correct type library version number. The latter part should be the problem.If the target machine runs a 64-bit version of Windows, try setting the Project + Properties, Build, Platform Target to x86.
Had the same problem with the following code:
Replacing the first line with the following solved it for me.
(sample in VB but same should apply to C#)
This can also happen, when you have uninstalled an office 2013 installation and you return to office 2010. There might be some registry keys and dlls left, which cause the office application to load the wrong dll(s).
Here is the fix: http://www.fieldstonsoftware.com/support/support_gsyncit_2013.shtml
If you attempt to access Outlook from Visual Studio and get the error:
TF400424: Failed to send to Microsoft Outlook: 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: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
Do the following:
Outlook 2007 ==> 9.3
Outlook 2010 ==> 9.4
Outlook 2013 ==> 9.5
Reference: https://support.netdocuments.com/hc/en-us/articles/205219170--Library-Not-Registered-error-when-using-EMS-in-Outlook