1

I have an C# winform app compiled for x86 platform, using excel 2003 COM interop libraries. The Visual studio project references the following interop files for office 2003)

Microsoft.Office.Interop.Excel.dll (v 11.0.0, specific version = true) Microsoft.Vbe.Interop.dll (v 11.0.0, specific version = false)

This application runs fine on most computers with excel 2003,2007 and 2010, but one of the users reported the exception below to me.

This users has windows 7 and Office 2010

System.InvalidCastException: Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).

   at Microsoft.Office.Interop.Excel.ApplicationClass.get_Workbooks()

From what I've read, this problem can occurs with conflicting versions of Office, but as I'm specifically referencing the 2003 Office PIAs and distributing them alongside the application, I'm unsure of what can cause the problem.

Thanks

David
  • 33,444
  • 11
  • 80
  • 118
  • Have you seen [this](http://social.msdn.microsoft.com/Forums/en-US/6b793878-d94a-4a62-8817-dea1cab79377/interopexcel-after-uninstalling-office-2007-and-installing-office-2003?forum=vbinterop) – Siddharth Rout Nov 28 '13 at 18:42
  • Yes I have, but in my scenario I'm correctly referencing the PIA (v11, Excel 2003) that the client should use – David Nov 28 '13 at 18:54
  • Is lateBinding an option that you can exercise? This way you don't have to worry about what ever version the destination pc has. – Siddharth Rout Nov 28 '13 at 19:03
  • possible duplicate of [Error accessing COM components](http://stackoverflow.com/questions/12957595/error-accessing-com-components). You have a very good solution here. – nawfal Nov 28 '13 at 19:17
  • @Siddharth: it'll take a while to modify all the code, so I'd prefer to fix the registry if I can – David Nov 29 '13 at 17:51

1 Answers1

2

The user's registry is broken. He has Office installed or you would have never been able to get the Aplication object created but it is missing an entry in the Typelib registry key. It is required to allow the interop call to succeed.

Reinstalling Office is the sane and simple solution. This kind of lossage is rarely isolated.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536