I have a .net Application that uses Microsoft.Office.Interop.Excel
nuget which is giving error in Office 2021 version.
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)).
It was working fine with Office 2019 version but this issue is occurring with Office 2021 version.
I also tested that this issue is occurring only after installing access db engine 2016 x64 version: 16.0.5044.1000 (which is required component for the application to function properly).
I have tried uninstalling and reinstalling the Office 2021 but the issue still persists. Repairing the Office 2021 version solved the issue for one time. Next day it is causing same error. I have to do repair every time the issue occurs.
Why multiple repair is required? Is there any other approach to solve the issue apart from Office Repair?
Environment:
.NetFramework 4.7.2
Code to reproduce Issue:
using Microsoft.Office.Interop.Excel;
public class ExcelOperations
{
private readonly _Application _excel;
private Workbook _workbook;
public ExcelOperations(string path)
{
_excel = new Application();
_workbook = _excel.Workbooks.Open(path); // Error line COM Exception
}
}