locked
System.InvalidCastException: 'Unable to cast COM object of type 'Microsoft.Office.Interop.Word.DocumentClass' RRS feed

  • Question

  • Hello,

    I have Office 365 installed on my machine. Particularly MS Word version is 2012.

    I have created C# project (VS 2019) and referenced microsoft word 16.0 object. It appeared as C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Office.Interop.Word\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll.

    at that following code

    Application application = new Application();
    var document = application.Documents.Open(args[0])

    throws

    System.InvalidCastException: 'Unable to cast COM object of type 'Microsoft.Office.Interop.Word.DocumentClass' to interface type 'Microsoft.Office.Interop.Word._Document'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{0002096B-0000-0000-C000-000000000046}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).'
    exception. I have checked \HKEY_CLASSES_ROOT\Wow6432Node\Interface\{0002096B-0000-0000-C000-000000000046}\TypeLib registry entry and it is empty (my machine is 64 bit).

    I tried to run my executable on other machines but  got the same error. Please advise.

    Thanks.
    Tuesday, December 8, 2020 1:03 AM