Retrieving the COM class factory for component error while generating word document

I am trying to edit a word document from VB.NET using for the most part this code:

How to automate Word from Visual Basic .NET to create a new document
http://support.microsoft.com/kb/316383

It works fine on my machine but when i publish to the server i get the following error.

Retrieving the COM class factory for
component with CLSID
{000209FF-0000-0000-C000-000000000046}
failed due to the following error:
80070005.

Description: An unhandled exception occurred during the
execution of the current web request.
Please review the stack trace for more
information about the error and where
it originated in the code.

Exception Details: System.UnauthorizedAccessException:
Retrieving the COM class factory for
component with CLSID
{000209FF-0000-0000-C000-000000000046}
failed due to the following error:
80070005.

The actual error happens when i try to just create a word application object

 Dim oWord As New Word.Application

Using Visual Studio 2008 and VB.NET 3.5. I made a reference to the “Microsoft Word 10.0 Object Library” and i see Interop.Word.dll file in the bin directory.

Using MS Office 2003 on development machine and Windows Server 2003

Still fairly new to .NET and don’t have much knowledge about window server, but “UnauthorizedAccessException” sounds like a permission issue. I’m wondering if someone could point me in the right direction on what i might need to do to give my little application access to use word.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

It definitely sounds like a permissions problem. Are you running your code in a windows service? The service normally runs as Local System, which may not have permission to access the Word object model. Additionally, if word is already running using the credentials of some other user then your program may not be able to access it via COM using different credentials. The office applications tend to be single instance which seems to exacerbate this problem.

Method 2

In my case, Word is running through a Windows Service under a service account.

The problem was that the Desktop folder didn’t exist in C:WindowsSystem32configsystemprofile (or in C:WindowsSysWOW64configsystemprofile).

Adding it resolved the issue for me.

Method 3

It sounds like you may have a permission issue in DCOM. Try editing the Word permissions in DCOM config.

Method 4

This appears to be what you are experiencing.

http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/006cbbac-101a-40ea-ae16-d59a7a2da8b1

Method 5

I was experiencing the same issue and the problem area I found was “security configuration for Microsoft Word in DCOM”. On the following link you can find a step by step guide to know how to config components in DCOM, repeate these steps for WORD, and your problem will be solved.

http://www.biocompsystems.com/_public/DCOMConfigurationStepbyStepForXP.doc

Thanks,
Sushil Jinder

Method 6

I had the same issue on Windows 2008 R2. Ended up using this post:
http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/65a355ce-49c1-47f1-8c12-d9cf5f23c53e

and then changing the impersonation identity user in web.config to another user to solve it.

I’m sure there is a combination of solutions.

Method 7

Go to Start -> Run
type regedit -32 and press enter key.

Registry Editor will get open.

Go To registry HKEY_CLASSES_ROOTWord.Application

Select Word.Application and set full permission to below users:-

Administrator, Administrators, Local Service, System, Service, Interactive and Users.

Method 8

I had the same problem while generating word document. The issue i solved by checking the task manager, and by ending the currently running process WINWORD.EXEs and then executed my code again. The issue gone.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x