1
votes

I have a PC with MS Office 2010 installed while the MS Outlook is installed from Office 2007. On this PC the below code:

Microsoft.Office.Interop.Outlook.Application myOutlook = new Microsoft.Office.Interop.Outlook.Application();
string theName = myOutlook.Name;

results into the below exception:

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)).

I have deleted the below registry entry and the above code was working normally. As soon as the Windows Updates run, the below entry is inserted again and the above code raises the exception again. HKEY_CLASSES_ROOT\TypeLib{00062FFF-0000-0000-C000-000000000046}\9.4

1) The registry entry cannot be deleted from the application due to permissions

2) The two office versions are needed

3) The line "string theName = myOutlook.Name;" can be replaced by any line referencing the variable myOutlook with exactly the same result

4) The same code works perfectly on PCs with MS Office 2007 installed, including MS Outlook.

Any suggestion will be much appreciated.

1
That is the type library for Outlook 2010. Sure, deleting it doesn't do you any good, Office knows how to repair such damage. This isn't going anywhere until you figure out how to get Outlook 2007 to co-exist with Office 2010. As unlikely that seems to be possible, this is not on topic here. Use superuser.com - Hans Passant
By deleting that registry entry the above code works normally. Since Outlook 2010 is not installed in the system I was hoping to find a way to get rid of it. - Chris

1 Answers

0
votes

You can use the late binding tachnology which can help to avoid such exceptions. See Type.InvokeMember method for more information.

Do you have the Click2Run edition of Office 2010 installed on the PC?