Cannot run MS Word app anymore using Microsoft.Office.Interop.Word in all of my VB.Net 4.8 programs

Wolf Schubert 20 Reputation points
2025-09-07T17:07:21.5333333+00:00

When running a Visual Studio 2022 test program with Imports Word = Microsoft.Office.Interop.Word I cannot run the program.

It fails with "Unhandled Exception: System.InvalidCastException: Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'."

Source code:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    ' Date:     9/6/2025 WS

    Cursor = Cursors.WaitCursor

    Dim WordApp As New Word.Application

    Dim WordDoc As New Word.Document

    Try

        WordApp = GetObject(, "Word.Application")

        WordApp.Visible = True

        WordApp.ActiveDocument.Activate()

        WordApp.Documents.Open("TestDoc.docx")

    Catch ex As Exception

        lblErrorMsg.Text = ex.ToString

        Application.DoEvents()

    Finally

        WordApp.Quit(False)

        WordApp = Nothing

        System.GC.Collect()

        Cursor = Cursors.Default

    End Try

End Sub

This happens with all of my VS 2022 programs which were working fine previously.

VBNet_TestWordApp_1.jpg VBNet_TestWordApp_2.jpg VBNet_TestWordApp_3.jpg VBNet_TestWordApp_4.jpg VBNet_TestWordApp_5.jpg VBNet_TestWordApp_6.jpg VBNet_TestWordApp_7.jpg VBNet_TestWordApp_8.jpg VBNet_TestWordApp_9.jpg VBNet_TestWordApp_10.jpg VBNet_TestWordApp_Form1_1.jpg VBNet_TestWordApp_Form1_2.jpg VBNet_TestWordApp_Form1_3.jpg VBNet_TestWordApp_Form1_4.jpg

Developer technologies | Visual Studio | Testing
{count} votes

Answer accepted by question author
  1. Varsha Dundigalla(INFOSYS LIMITED) 2,785 Reputation points Microsoft External Staff
    2025-09-08T09:25:50.24+00:00

    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)

    1. 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) or x64 (for 64-bit Word).
      Avoid “Any CPU.”
      Configure projects to target platforms
    1. 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
    1. 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
    1. Re-add the Interop Reference
    1. Consider Alternatives for Server or Background Use

    Microsoft does not recommend automating Office in unattended or server environments. For these cases, consider:

    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.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Wolf Schubert 20 Reputation points
    2025-09-07T21:11:50.23+00:00

    I tried that and the result is the same.

    Even when I comment out the following 2:

            ''WordApp = GetObject(, "Word.Application")
    
            ''WordApp.Visible = True
    
            ''WordApp.ActiveDocument.Activate()
    
            WordApp.Documents.Open("TestDoc.docx")
    
        Catch ex As Exception
    
            lblErrorMsg.Text = ex.ToString
    
            Application.DoEvents()
    

    I still get this failure when executing the last one (WordApp.Documents.Open("TestDoc.docx").

    0 comments No comments

  2. Wolf Schubert 20 Reputation points
    2025-09-09T00:18:19.13+00:00

    This response was one of the best I've ever seen. Thank you.

    The problem was, it turns out, your

    "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."

    Office 32bit was running on a Windows 64bit system.

    My application compiles and runs now perfectly under Office Pro 64bit and Windows 11 24H2 64bit.

    I also had to move the "WordApp.ActiveDocument.Activate()" statement after the Open statement.

    WordApp = GetObject(, "Word.Application")

    WordApp.Visible = True

    WordApp.Documents.Open("TestDoc.docx")

    WordApp.ActiveDocument.Activate()

    (I switched from Windows 10 to Windows 11 also.)

    Thank you for your fast response. Breathing fresh air now. :-)


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.