logo
search
Excel Error Codes

Fix Excel COM Interface Cast Errors in .NET Framework x64 Builds

Maira MehtabMaira Mehtab Sep 20, 2026 869 views

Question details

Users experience a COM interface cast error when running a .NET Framework 4.7.2 application built for x64 utilizing Microsoft.Office.Interop.Excel with Office 2021.

Product
Microsoft Excel 2021 / .NET Framework 4.7.2
Device & OS
not provided
Scenario
Developing and compiling a .NET Framework application targeting the x64 architecture and interacting with Excel via COM interop.
Observed behavior
The application throws a COM interface cast error specifically on x64 builds, while x86 or Any CPU configurations function properly.
Before you start

Verify your project's build configuration settings in Visual Studio and ensure all Microsoft.Office.Interop.Excel assembly references are up to date.

Solution 1Recommended

Repair the Microsoft Office Installation

Running a repair on Microsoft Office 2021 often resolves broken 64-bit COM interoperability registry keys that cause cast errors.

COM interface cast errors on specific architectures usually stem from corrupted or missing registry configurations for the Office installation rather than your code.

1
Open Windows Settings

Navigate to the Windows Control Panel or open the Settings app and go to 'Apps & features' (or 'Installed apps').

2
Select Office 2021

Scroll through the list of installed programs, locate Microsoft Office 2021, and select 'Modify' or 'Change'.

3
Run Quick Repair

Choose the 'Quick Repair' option and follow the on-screen prompts. If the issue persists after completion, try the 'Online Repair' option.

Build Test: After the repair completes, clean and rebuild your .NET solution for x64 to confirm the interface cast error is resolved.
Free Microsoft Office alternative

Discover WPS Office as a Lightweight Alternative

Experiencing stubborn COM interop issues and registry errors with Microsoft Excel? Consider switching to WPS Office, a highly compatible, fast, and free alternative that handles all your standard spreadsheet tasks without the heavy registry footprint.

  1. 1. Download the Installer: Visit the official WPS Office website and download the free installation package.
  2. 2. Install WPS Office: Run the downloaded executable file and follow the quick setup wizard.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheets and effortlessly open your existing Excel documents.
Completely free to use with zero subscription feesSeamless compatibility with Microsoft Excel (.xlsx, .xls) formatsFamiliar user interface makes transitioning effortlessLightweight installation that won't bloat your system registry
microsoft office alternative - wps office

Frequently Asked Questions

Why does the Excel COM interface cast error only happen on x64 builds?

This typically occurs due to mismatched, unregistered, or corrupted 64-bit registry keys for Microsoft.Office.Interop.Excel on the host machine, while the 32-bit (x86) keys remain intact and functional.

What does the Prefer32Bit setting do in .NET Framework?

The 'Prefer32Bit' flag forces an 'Any CPU' application to run as a 32-bit process on 64-bit systems. This often inadvertently bypasses 64-bit COM interop errors by utilizing the functioning x86 Office registry paths.

Can reinstalling the Microsoft.Office.Interop.Excel NuGet package fix this?

Usually, no. If the issue stems from a corrupted local Office installation registry, updating or reinstalling the NuGet package will not resolve it. Repairing the actual Microsoft Office application is required.