'Why do Office updates break the Excel interop?
I'm writing Selenium automation in C# in Visual Studio 2019, and have a Microsoft Office 16.0 Object Library COM reference so that I can open Excel sheets and read in data. The version of Excel I'm using is "Microsoft Excel for Microsoft 365 MSO (16.0.13801.21198) 32-bit".
The Excel code works fine until certain Office updates are rolled out to my machine, at which point I start getting this error when trying to open a worksheet:
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.
I've seen various recommendations to try deleting a registry entry in order to fix this, which have not worked. The only way I can get it working again is to run a Quick Repair on Office 365.
This is happening every week or two, and I have a number of automation developers on my team who have the same issue and need to run a Quick Repair in order to fix it.
Does anyone know exactly what causes this problem? I'd really prefer to develop a solution or workaround for it that doesn't require manually firing off a repair to Office all the time.
Note: I have tried switching to the Excel.Interop nuget package and using that dll instead but I still have the same issue after an Office update.
Solution 1:[1]
I think that switching to a package that doesn't use a COM object might work. When I ran into a problem sort of like this I switch to using EPPLus it is licened but you can use it without if it is not comercial.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | GlasjeWater |
