Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))



    My current code ran in VS2003 on a XPpro machine. I transferred it to a Vista machine and had to purchase VS2005 . I made the changes and the code ran. I made additions over several weks and the code still ran . I did not run the code a gain for about a month and then the code would not run on the Vista machine so I installed VS2005 on an XPpro PC and the same then code compiiles and runs fine.


    Both PCs have Ofiice 2003 Pro on them and no other versions of Excel or office.


    It as if one of  the MS regular Vista updates made a change causing the code not to compile.


    My code is in Visaul Basic


    These are the first lines of the code


    Imports System.IO

    Imports System.IO.StreamReader

    Imports System

    Imports System.Threading

    Imports System.text.regularexpressions

    Imports System.Text

    Imports System.Globalization

    Imports System.Collections

    Imports Microsoft.Office.interop.excel

    Imports Excel = Microsoft.Office.Interop.Excel

    Imports System.Reflection

    Imports System.Runtime.InteropServices


    The lines following this are Windows Form Designer Generated code (about 2000 of them ) Total program is about 9000 lines


    Dim ExcelScheduler As New Excel.Application

    Dim ExcelWB As Excel.Workbook = ExcelScheduler.Workbooks.Open("C:\ExactaRecords\Scheduler.xls")

    Dim ScheduleSheet1 As Excel.Worksheet = ExcelWB.Sheets(1)

    Dim ScheduleSheet2 As Excel.Worksheet = ExcelWB.Sheets(2)

    Dim ScheduleSheet3 As Excel.Worksheet = ExcelWB.Sheets(3)


    ScheduleSheet1 = ExcelWB.Worksheets(1)

    ScheduleSheet2 = ExcelWB.Worksheets(2)

    ScheduleSheet3 = ExcelWB.Worksheets(3)


    This is the error message:


    System.InvalidCastException occurred
      Message="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()
           at ShowTimeScheduler.ShowTimeDirector..ctor() in C:\ShowTimeScheduler\Backup\ShowTimeDirector.vb:line 2222

    Error occurs at the line :


    Dim ExcelWB As Excel.Workbook = ExcelScheduler.Workbooks.Open("C:\ExactaRecords\Scheduler.xls")



    Does any one have any ideas how to fix this problem?


    Monday, May 05, 2008 10:37 PM


All replies

  • Hi,


    One thing you could try is running 'Microsoft.Office.Interop.Excel.dll.reg', 'Microsoft.Vbe.Interop.dll.reg' and 'office.dll.reg' located in InstallationFolder..PIAs..

    Also, It could be that you need to compile your project against the oldest version of (Primary) Interop Assembly (


    And I think you should also post this question in Office developer news group in Excel:


    hope that this helps,



    Tuesday, May 06, 2008 12:44 AM
  • Thanks for the suggestions. This did work daily for a month with Vista and Office11 interops and still works under XPpro on a seocond PC. I did try removing all references to 11.0 and tried earlier interops . I also cleaned the registry of all references to office and reinsatlled office 2003 pro and VS 2005 to no effect. If I remark out all references to Excel objects the program complies and runs all of the other tasks so it is most likely an Excel or Vista related issue.


    I will post the problem on a Excel site. I have searched the web and there are about a hundred references to the same problem with other office objects but no where has any one posted and answer except when using Office 2007 Interterops instead of 2003.


    Tuesday, May 06, 2008 12:58 AM