none
How to fix e 'System.InvalidCastException Unable to cast COM object of type;Microsoft.Office.Interop.Excel.ApplicationClass to interface type 'Microsoft.Office.Interop.Excel._ RRS feed

  • Question

  • 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: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

    Hi,

    The above error occurs when I try to excute the code which searches a value in excel and returns the .offset to textboxes. I have deleted the .bin & project folders and build the project again but still facing the error. How to fix this? Is it the way am using excel going wrong?

    Thanks

           
    Imports Excel = Microsoft.Office.Interop.Excel
    Imports System.Data.OleDb
    Imports System.Runtime.InteropServices
    
    
    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
    
            Dim xlappFile As Excel.Application = New Excel.Application
            Dim xlFile_WB As Excel.Workbook = Nothing
            Dim xlFile_WS As Excel.Worksheet = Nothing
            Dim xlFirstfile_WS1 As Excel.Worksheet = Nothing
            Dim FoundRange As Excel.Range
            Dim lastrow, lastcolumn As Long
            Dim searchID As String
            searchID = APpittagX.Text
            Dim startcell As Range
            Try
                xlappFile.Workbooks.Open(destination1)
                'xlFile_WB = xlappFile.Workbooks(destination1) ' destination1 is selected by 'user
    
                MessageBox.Show(destination1)
                xlFile_WS = xlappFile.Worksheets("Individlist")
    
                startcell = xlFile_WS.Range("A1")
                lastrow = xlFile_WS.Cells("B" & xlFile_WS.Rows.Count).End(Excel.XlDirection.xlUp).Row
                lastcolumn = xlFile_WS.Cells("A2", xlFile_WS.Columns.Count).end(Excel.XlDirection.xlToLeft).column
                FoundRange = xlFile_WS.Cells.Range(lastrow, lastcolumn).Find(What:=searchID, LookIn:=Excel.XlFindLookIn.xlFormulas, LookAt:=Excel.XlLookAt.xlPart)
    
                If FoundRange Is Nothing Then
                    APaliasX.Text = "not found"
                    APFamilieX.Text = "not found"
                    APFarX.Text = "not found"
                    APFam_RankX.Text = "not found"
                    APFamindeksX.Text = "not found"
                Else
                    APaliasX.Text = FoundRange.Offset(0, -1).Value
                    APFamilieX.Text = FoundRange.Offset(0, 1).Value
                    APFarX.Text = FoundRange.Offset(0, 2).Value
                    APFam_RankX.Text = FoundRange.Offset(0, 3).Value
                    APFamindeksX.Text = FoundRange.Offset(0, 4).Value
                End If
            Catch ex As Exception
                MsgBox(ex.ToString)
    
            Finally
    
                GC.WaitForPendingFinalizers()
                ReleaseObject(xlFile_WS)
                ReleaseObject(xlFile_WB)
                xlappFile.Quit()
                ReleaseObject(xlappFile)
            End Try
        End Sub
        Private Sub ReleaseObject(ByVal ob As Object)
            Try
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ob)
            Catch
            Finally
                ob = Nothing
                GC.Collect()
                GC.WaitForPendingFinalizers()
            End Try
        End Sub 
    

    NewBInVB




    • Edited by NewBInCoding Wednesday, November 23, 2016 3:10 PM
    • Moved by Neda Zhang Thursday, November 24, 2016 8:23 AM Moved from vb forum
    Wednesday, November 23, 2016 2:38 PM

Answers

  • Thanks I have fixed this by deleting the TypeLib > 1.9 in regedit HKey Local and installed Excel again.  

    NewBInVB

    • Marked as answer by NewBInCoding Thursday, November 24, 2016 2:20 PM
    Thursday, November 24, 2016 2:20 PM

All replies

  • 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: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

    Firstly, check your references.   Make sure that you have included all required references, and that you have not included multiple copies of the same item at different revision numbers, or references to different versions of Excel. 

    If the references are correct, then this is likely a problem with the installation of Excel.  The type library registration is incomplete or has been overridden or corrupted, or the library itself is deleted, corrupted or the wrong version.  If you search on "000208D5-0000-0000-C000-000000000046" you will find many references to this problem, usually associated with having multiple versions of Excel installed on the machine, or installed in the wrong sequence.

    Wednesday, November 23, 2016 8:07 PM
  • Hi NewBlnVB,

    Thank you for posting in MSDN Forum.

    Since your issue is more related to Excel, I will move this thread to Excel for Developers forum for better support.

    Thanks for your understanding and support.

    Best Regards,

    Neda Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 24, 2016 8:21 AM
  • Thanks I have fixed this by deleting the TypeLib > 1.9 in regedit HKey Local and installed Excel again.  

    NewBInVB

    • Marked as answer by NewBInCoding Thursday, November 24, 2016 2:20 PM
    Thursday, November 24, 2016 2:20 PM
  • I had this exact same error, albeit I was developing with C# in Visual Studio 2017. What solved the problem for me was to do an online repair of Office 365 that is installed on my dev box.

    Hoping this helps someone else...

    Sunday, November 12, 2017 5:54 PM
  • Repair of Office 365 for me fixed problem too.
    Tuesday, July 28, 2020 9:09 AM