Microsoft Interop Assembly for Excel Fails

a b 1 Reputation point
2020-09-25T20:22:31.843+00:00

Does Microsoft.Office.Interop.Excel work in x64 and Any CPU modes after updating MS Office 2019? My application fails when attempting to add a workbook with:

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: Element not found. (Exception from HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND)).

I've included the assembly via a reference to 'Microsoft Excel 16.0 Object Library' in the Com reference area. When I query the Excel application object, I see the following (only a partial list):

?cfExcel
{Microsoft.Office.Interop.Excel.ApplicationClass}
ActiveCell: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).ActiveCell' threw an exception of type 'System.InvalidCastException'
ActiveChart: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).ActiveChart' threw an exception of type 'System.InvalidCastException'
ActiveDialog: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).ActiveDialog' threw an exception of type 'System.InvalidCastException'
ActiveEncryptionSession: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).ActiveEncryptionSession' threw an exception of type 'System.InvalidCastException'
ActiveMenuBar: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).ActiveMenuBar' threw an exception of type 'System.InvalidCastException'
ActivePrinter: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).ActivePrinter' threw an exception of type 'System.InvalidCastException'
ActiveProtectedViewWindow: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).ActiveProtectedViewWindow' threw an exception of type 'System.InvalidCastException'
ActiveSheet: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).ActiveSheet' threw an exception of type 'System.InvalidCastException'
ActiveWindow: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).ActiveWindow' threw an exception of type 'System.InvalidCastException'
ActiveWorkbook: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).ActiveWorkbook' threw an exception of type 'System.InvalidCastException'
AddIns: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).AddIns' threw an exception of type 'System.InvalidCastException'
AddIns2: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).AddIns2' threw an exception of type 'System.InvalidCastException'
AlertBeforeOverwriting: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).AlertBeforeOverwriting' threw an exception of type 'System.InvalidCastException'
AltStartupPath: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).AltStartupPath' threw an exception of type 'System.InvalidCastException'
AlwaysUseClearType: 'DirectCast(cfExcel, Microsoft.Office.Interop.Excel.ApplicationClass).AlwaysUseClearType' threw an exception of type 'System.InvalidCastException'

My application is compiled for 'Any CPU' and each project does not have the 'Prefer 32 bit' property set.

Any suggestions?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
41,484 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2020-09-25T20:27:11.147+00:00

    Excel development is not currently supported here on QnA. They're actively answering questions in dedicated forums here.
    https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-msoffice_custom
    https://social.msdn.microsoft.com/Forums/Lync/en-US/home?forum=exceldev
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vsto

    --please don't forget to Accept as answer if the reply is helpful--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.