views:

329

answers:

1

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.

+2  A: 

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
On Windows x64, learn about WOW64 registry (http://support.microsoft.com/kb/896459)
Lex Li
@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
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