Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.UnauthorizedAccessException: Retrieving the COM class factory for Word Interop fails with error 80070005

Tags:

c#

.net

windows-7

I have a problem with a C# ASP .NET project in Visual Studio 2008 This problem started when I reinstalled my computer with Windows 7 Ultimate (x64). To this I'm also using Office 2007.

The error message I'm getting is:

System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005. at xxx.Utility.WordDocument..ctor(String filePath, HttpServerUtility util) at customer_communication.BuCreate_click(Object sender, EventArgs e) in c:\xxx\Website\customer\communication.aspx.cs:line 127

like image 458
Tomas I Avatar asked Sep 29 '09 07:09

Tomas I


4 Answers

Here is my fix for this problem:

I'm using Win 7 64bit and Office 2007

Run program "dcomcnfg -32". ( You cant find the word and excel components if it runs under 64bit)

Go to "Console Root/Component Services/Computer/My Computer/DCOM Config/" Look up Microsoft Word and Excel and choose properties.

Go to Security and select "Customize" under "Configuration Permissions. (If needed you might want to change the other permissions as well, but I didn't need to) Add "IIS_IUSRS" and give it "Full Control".

Now go to "Identity" and select "The interactive user".

Do not forget to press "OK" when done. :D

I Hope this helps you with your problem and also the rest who gets here and read this.

like image 77
Tomas I Avatar answered Oct 21 '22 18:10

Tomas I


You should grant an access to Word COM component for ASP.NET process identity ({MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6):

"Control Panel - Administrative Tools - Component Services - Computers - My Computer - DCOM Config"

Find out "Microsoft Word Document", right click - Settings - Security Tab, grant access (local and remote) for ASP.NET process identity ("ASPNET" for IIS 5, "Network Service" for IIS 6).


If then you get an "System.Runtime.InteropServices.COMException (0x800A13E9): There is insufficient memory. Save the document now." exception when open/add document (my own expirience), just delete temporary files from %Temp% and \Content.Word folders.

like image 33
Serge S. Avatar answered Oct 21 '22 17:10

Serge S.


launching dcomcnfg -32 or dcomcnfg /32 both failed to show the target app (Microsoft Excel) in the list.

But my following the directions @ How to make IIS7 play nice with Office Interop, in particular, the note about launching mmc -32 and manually adding in the Component Services snap-in, I was able to get it to appear. (NOTE: although the link talks about IIS7, my issue was with a Windows service).

  1. Start > Run > dcomcnfg (or “mmc -32″ and then add the Component Services snap-in manually if you can’t find the app under step 3)
  2. Navigate to Component Services > Computers > My Computer > DCOM Config
  3. Locate the MS application giving you trouble (eg: “Microsoft Excel Application” for Excel or “Microsoft Word 97 – 2003 Document” for Word)
  4. Right click > Properties
  5. On the security tab: Select Customize under Launch and Activation Permissions and click Edit…
  6. Add the account under which the site is running (eg: Network Service) and assign Local Launch & Local Activation permissions
  7. Voila!
like image 8
Michael Paulukonis Avatar answered Oct 21 '22 17:10

Michael Paulukonis


This worked for me:

  1. In the command line put DCOMCNFG
  2. Component Services -> Computers -> My Computer -> DCOM Config
  3. Find "Microsoft Word 97 - 2003 Document" (If it is missing check if your Word is also 64 bit)
  4. Right click -> Properties
  5. Go To Tab Security and Edit the "Customize" radio buttons so that IIS_IUSRS could have rights for launch and access
  6. Go to Tab Identity and choose "The interactive user"
  7. Apply changes and try again
  8. If all this fails, go also to tab "General" and in "Authentication Level" drop down choose "None".
like image 6
gyosifov Avatar answered Oct 21 '22 18:10

gyosifov