1

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);
William Wong
  • 21
  • 1
  • 3
  • You could use a tool such as Process Monitor from sysinternals to check what registry keys are really used (filter on your process name to avoid millions of traces...). – Simon Mourier May 11 '19 at 07:45
  • A proper re-install could suffice? – Amen Jlili May 11 '19 at 07:50
  • 1
    Having such a gross version mismatch is no doubt the problem. Microsoft was able to keep the interop compatible for a very long time but that's been running out of gas. Version number are hard to track, I *think* that Word 2016 was version 2.8 so 3.0 sounds right for 2019. A major version number change must always be considered breaking. Very important to have 2019 installed on your dev machine so you can build your program with the correct type library. And to **not** use the olden PIA as a reference in your project. https://stackoverflow.com/a/21018418/17034 – Hans Passant May 11 '19 at 10:58
  • In your place, trying to troubleshoot this, I'd start in Excel VBA and see if `New Word.Application` works there. If it doesn't, then you might get a more informative message and you can be fairly sure the problem is in the Registry. If it does work, then it narrows down the problem to the .NET "interop". – Cindy Meister May 11 '19 at 13:52

3 Answers3

0

I had a very similar issue where an application runs fine on a bunch of machines, but was giving this error on another one. Turns out installed version of Office was 64-bit and was causing the problem.

After installing the 32-bit version, everything works fine.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
0
  1. Reinstall word (keep the latest version if you have more than 1)

  2. If you have word library object reference in your project, then make sure your client pc has it so open regedit and search for :

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TypeLib{00020905-0000-0000-C000-000000000046}\x.x

where x.x is the word library version

If you have more than one x.x, delete the one thats empty, that should solve it!

Cedric
  • 672
  • 7
  • 17
0
  1. Reinstall word (keep the latest version if you have more than 1)

  2. If you have word library object reference in your project, then make sure your client pc has it so open regedit and search for :

    Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TypeLib{ 00020905-0000-0000-C000-000000000046}\x.x

    where x.x is the word library version

  3. If you have more than one x.x, delete the one thats empty, that should solve it!