9

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.

PK.
  • 588
  • 1
  • 4
  • 12

4 Answers4

10

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

Daniel Ranft
  • 116
  • 1
  • 2
  • 3
    Awesome find - deleting `HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046}\9.5` did the trick! This is an error with the **Office 2013 uninstaller**. – SliverNinja - MSFT Sep 18 '12 at 21:09
  • 1
    Good find, that fixed my problem +1 – Gabe Sep 18 '12 at 21:13
  • That 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. – Doigen Feb 14 '15 at 18:42
5

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 to HKEY_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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • On Windows x64, learn about WOW64 registry (http://support.microsoft.com/kb/896459) – Lex Li Feb 28 '10 at 00:27
  • @nobugz: about that second step: when I navigate to that location value stored in there says "value not set". is that a problem? should it be set to a specyfic value? if so what value shoud be there. In child nodes of HKEY_CLASSES_ROOT\TypeLib\{00062FFF-0000-0000-C000-000000000046} a have some emty values as well. shoud they be set? – PK. Mar 01 '10 at 00:09
  • Well, that explains why it doesn't work. No idea what happened, chase the "not properly installed" angle. Maybe your registry is toast, try it on another machine. – Hans Passant Mar 01 '10 at 00:53
  • 1
    Turned out to be the build platform for me. Thanks! – shookdiesel Feb 12 '13 at 11:18
1

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:

  1. Using the Registry, navigate to: HKEY_CLASSES_ROOT\TypeLib{00062FFF-0000-0000-C000-000000000046}
  2. Delete the version keys (e.g. 9.5) for any version of Outlook that is not installed on your system based on the version table provided below. For example, if you are not using Outlook 2013 then remove the "9.5" entry. If you are not using Outlook 2010 then remove the the "9.4" entry. DO NOT DELETE the entry for the version that was configured in Step #1

Outlook 2007 ==> 9.3

Outlook 2010 ==> 9.4

Outlook 2013 ==> 9.5

enter image description here


Reference: https://support.netdocuments.com/hc/en-us/articles/205219170--Library-Not-Registered-error-when-using-EMS-in-Outlook

zumalifeguard
  • 8,648
  • 5
  • 43
  • 56
0

Had the same problem with the following code:

Dim OutlookMessage As Outlook.MailItem
Dim AppOutlook As New Outlook.Application
OutlookMessage = AppOutlook.CreateItem(Outlook.OlItemType.olMailItem)

Replacing the first line with the following solved it for me.

 Dim OutlookMessage As Object

(sample in VB but same should apply to C#)

Striver
  • 451
  • 6
  • 7