Thank you for sharing details.
Why This Happens
When your VB.NET application automates Microsoft Word, it communicates through a COM proxy. Your project is compiled against an interop assembly (Microsoft.Office.Interop.Word) that defines the interfaces and methods expected at runtime.
This error occurs when the COM proxy Word provides doesn’t match the interop type your app expects. Common causes include:
Bitness mismatch
Word is installed as 32-bit but your app runs as 64-bit (or vice versa). A 32-bit Office cannot be automated from a 64-bit process.
Interop version or embedding differences
Your project may use embedded interop types or a different version of the PIA than the installed Office.
Broken COM registration
Office updates or Click-to-Run installations can alter or break registry entries for Word’s COM classes.
Conflicting assemblies
Multiple versions of the interop DLLs in the GAC or your project can confuse .NET into binding to the wrong one.
Because .NET expects an exact match to _Application, any of these issues can cause a System.InvalidCastException.
Recommended Fixes (Try in This Order)
- Match Word Bitness with Your Project
- Open Word → File → Account → About Word → check if it’s 32-bit or 64-bit.
- In Visual Studio → Project Properties → Build → Platform Target → set to
x86(for 32-bit Word) orx64(for 64-bit Word).
Avoid “Any CPU.”
Configure projects to target platforms
- Check the Interop Reference Settings
- In Solution Explorer → select
Microsoft.Office.Interop.Word. - In Properties → set Embed Interop Types = False.
This ensures your app uses the installed PIA instead of embedded stubs.
Office primary interop assemblies
- Repair Microsoft Office
- Go to Control Panel → Programs → Programs and Features.
- Select Microsoft Office → Change → choose Quick Repair (and Online Repair if needed).
Repair an Office application
- Re-add the Interop Reference
- Remove the current
Microsoft.Office.Interop.Wordreference. - Re-add it manually or install the official NuGet package for a clean version.
Microsoft.Office.Interop.Word NuGet package
- Consider Alternatives for Server or Background Use
Microsoft does not recommend automating Office in unattended or server environments. For these cases, consider:
- Open XML SDK for Office
- Considerations for unattended automation of Office in the Microsoft 365 for unattended RPA environment
Summary
In most cases, correcting the Platform Target and setting Embed Interop Types = False resolves the error. If not, repairing Office and re-adding the reference usually helps.
If You Still See the Error
Please share the following details:
- The version of Microsoft Office (32-bit or 64-bit).
- Your Visual Studio Project’s Platform Target setting.
- The Embed Interop Types property value for the Word reference.
- Whether you’ve already tried an Office repair or reinstall.
This information will make it much easier to pinpoint the cause and suggest the next step.
Let me know if you need any further help with this. We'll be happy to assist.
If you find this helpful, please mark this as answered.