Results 1 to 3 of 3

Thread: [RESOLVED] Unable to cast COM object, MSWord

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2020
    Posts
    39

    Resolved [RESOLVED] Unable to cast COM object, MSWord

    Just trying to sort an early binding issue with MSWord, created from a Winform.
    Code works as expected on Client machine but not on dev machine.

    It works fine if late binding

    Error:
    Code:
    An unhandled exception of type 'System.InvalidCastException' occurred in PTApplication.exe
    Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type Microsoft.Office.Interop.Word._Application'. 
    This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error:      Interface not registered (Of Exception from HRESULT: 0x80040155).
    Steps
    -Googled
    -Appears to be registry problem with various previous Office installs
    -Tried recommended reg fixes, same issue
    - Removed Office, ran Microsoft repair tool to remove ALL traces of Office
    - Reinstalled Office365
    - Same issue exists.
    - Removed analyzer for Microsoft.Office.Interop.Word
    - Added current version (although it showed it was the same version)
    - Rebuilt and ran code, same error
    - Checked registry once more, IID 00020970 does not exist, actual IID 00020905
    Actual path: Computer\HKEY_CLASSES_ROOT\TypeLib\{00020905-0000-0000-C000-000000000046}\8.7

    If I am correct, the issue appears to be analyzer pointing to wrong registry entry or an old reference still being used in code?

    Any suggestions as to what would change the COM component call to the right entry?

    Error images:
    Name:  Untitled1.jpg
Views: 4430
Size:  42.3 KBName:  Untitled2.jpg
Views: 4236
Size:  10.9 KBName:  Untitled3.png
Views: 4296
Size:  19.1 KB

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Unable to cast COM object, MSWord

    I have seen a couple of issues around this before. One option is to run Visual Studio as an administrator, the other is check the Prefer 32-bit option in your project's properties.

    It has been a long time since I've run into this, but I want to say one (or both) of those options solved my issue.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2020
    Posts
    39

    Re: Unable to cast COM object, MSWord

    Cheers for the options.

    > Run as Admin, no. Same error.
    > 32 bit already checked, removed and *BOOM* runs. Its obviously a 64/32 issue if thats the case, but now Ill need to see if it runs on the Client machine.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width