How to fix the exception, when I call new Microsoft.Office.Interop.Word.Application()

0

When I call new Microsoft.Office.Interop.Word.Application() to initialize, an error occurred. The message is as follows:

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: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).

Some help was obtained after searching in MSDN(this page). But when I checked HKEY_CLASSES_ROOT\Wow6432Node\Interface{00020970-0000-0000-C000-000000000046}\TypeLib, I found my "Version" is 3.0 instead of 8.6, "(Default)" is {00020905-0000-4B30-A977-D214852036FF} instead of {00020905-0000-0000-C000-000000000046}. And in HKEY_CLASSES_ROOT\Wow6432Node\TypeLib{00020905-0000-0000-C000-000000000046}, there should only be 1 subkey named 8.7 instead of 8.6.

I have tried to change the Version in HKEY_CLASSES_ROOT\Wow6432Node\Interface{00020970-0000-0000-c000-000000000046}\TypeLib to 8.7 and (Default) to {00020905-0000-0000-0000-c000-000000000046}, but it still doesn't work. I also, according to this page instructions try to "Quick Repair" and completely reinstall Office. How do I modify the registry keys to be successful?

My Word version is Professional 2019(Click-to-run).

In addition, I'm sure my code is correct. Because I wrote the code on another computer where it executed perfectly.

Here's a little bit of my code:

    Microsoft.Office.Interop.Word.Application wordApp;
    Microsoft.Office.Interop.Word.Document wordDoc;
    wordApp = new Microsoft.Office.Interop.Word.Application();
    wordApp.Visible = visible;
    Object Nothing = Missing.Value;
    wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
c#
ms-word
com
ms-office
office-interop
asked on Stack Overflow May 11, 2019 by William Wong

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0