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
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.
User contributions licensed under CC BY-SA 3.0