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?