COM Exception when using Microsoft.Office.Interop.Word

COM Exception when using Microsoft.Office.Interop.Word

corinne.astori
Advocate Advocate
7,139 Views
5 Replies
Message 1 of 6

COM Exception when using Microsoft.Office.Interop.Word

corinne.astori
Advocate
Advocate

Hi!

I am having a problem with the code in my Revit Add-in. In the code I use the Microsoft.Office.Interop.Word to make some changes in a Word document and then save it. All this works perfectly on my machine and on other 4 test machines. For some reasons one of the users is getting an error:

With Revit 2021:

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

With Revit 2020:

Element not found (Exception from HRESULT: 0x8002802B(TYPE_E_ELEMENTNOTFOUND))

 

On one of the testing machines, the same error occured when Microsoft Offfice was not installed. After installing MS Office the Add-in works as expected.

 

In know this is not a typical Revit API issue, but maybe some of you already experienced the same error.

Any help would be appreciated.

Thank you

Corinne

0 Likes
Accepted solutions (1)
7,140 Views
5 Replies
Replies (5)
Message 2 of 6

Revitalizer
Advisor
Advisor

Hi,

 

if you use COM for driving Word by your add-in, you need Word.

Same for COM for Excel.

 

Why not using Office Open XML?

http://www.ludovicperrichon.com/create-a-word-document-with-openxml-and-c/

 

This way, no Word installation is needed, at all.

Office Open XML can be used for Excel files, too.

 

No need for Office licences if you just want to read or write Office files.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 3 of 6

corinne.astori
Advocate
Advocate

@RevitalizerThank you for your answer.

The user says that he has MS Office installed on his machine! My problem is, the user experiencing the issue is not a “normal” user but an Autodesk employee who is testing my add-in before publishing it. So now my add-in is being hold back because of this error, kind of annoying…

Any other possible causes? Maybe is his MS Office installation corrupted?

 

I also thought of using Office OpenXML instead of the Word Interop, the only disadvantage for my specific needs is that you don’t have the possibility of saving the document file as PDF (as far as I know). But I will think again about this and maybe have to make some compromises.

 

Regards,

Corinne

0 Likes
Message 4 of 6

Revitalizer
Advisor
Advisor

Hi,

 

different Word versions 😞

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 5 of 6

corinne.astori
Advocate
Advocate

@Revitalizer 

According to Microsoft documentation this should not be an issue:

"If you embed type information from a strong-named managed assembly, you can loosely couple types in an application to achieve version independence. That is, your program can be written to use types from any version of a managed library without having to be recompiled for each new version."

https://docs.microsoft.com/en-us/dotnet/standard/assembly/embed-types-visual-studio

 

Did I missunderstand something?

0 Likes
Message 6 of 6

corinne.astori
Advocate
Advocate
Accepted solution

The problem was on the user machine. After he uninstalled MS Office and reinstalled it the error disappeard. Now the add-in works as expected.