34

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

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Tomas I
  • 721
  • 1
  • 8
  • 10
  • Maybe you should show us the content of the 'c:\xxx\Website\customer\communication.aspx.cs' file so we could have any idea what you're trying to do. – Joren Sep 29 '09 at 07:59
  • 2
    The COM Guid pings back lots of references on google to Microsoft Office, specifically version 2003. I would assume this is a direct result of not having the interop components for 2003 installed? – Gregory Sep 30 '09 at 03:47
  • 2
    epic title! I love it :D – Alastair Pitts Mar 02 '10 at 05:47
  • http://blog.crowe.co.nz/archive/2006/03/02/589.aspx – Thomas Apr 16 '13 at 12:51

11 Answers11

36

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.

Tomas I
  • 721
  • 1
  • 8
  • 10
  • 1
    Thanks for your post, it helped me fix my issue. You have to do the same steps for the "Microsoft Excel previewer" object. – thiag0 Apr 11 '11 at 18:31
  • 1
    The correct writing is `dcomcnfg /32` For further information see [this answer](http://stackoverflow.com/a/7767364/701988) – sra Dec 29 '11 at 12:41
  • 8
    I'm using Win7 64bit with Office 2010 (32bit), a in "Component Services" I don't see any info about MS Word. What can I do? – Jacek Oct 09 '12 at 10:31
  • The "starter" editions dont play well with office automation. So that could be one reason why they are not listed. – nawfal Feb 11 '14 at 09:45
  • This worked for me when I registered my console application as a task in Task Scheduler, however at 12:00 AM the next day this error recurred. Would you have an idea why? – Josh Monreal Mar 27 '18 at 02:02
  • @Jacek, I had the same issue with those not showing up. I had to add the Component Services snap-in via MMC, see Michael's answer below: https://stackoverflow.com/a/8566553/2088676 – Jordan Ryder Jan 11 '19 at 16:35
9

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.

Serge S.
  • 4,855
  • 3
  • 42
  • 46
  • 11
    I had the same problem but couldn't find "Microsoft Word Document" in DCOM Config. – Larry Watanabe Jul 12 '10 at 17:46
  • 1
    "Microsoft Word Document" is localized with your MS Office language. In Russian, for example it is named "Документ Microsoft Word". Also you can try to find it by CLSID {000209FF-0000-0000-C000-000000000046} in the right column (use table view). – Serge S. Jul 13 '10 at 06:54
  • The 'Local and Remote' options are within the 'Launch and Activation Permissions' group within the Security tab. – Ian Newson Jul 25 '12 at 18:51
  • 3
    I cannot able to find CLSID or Microsoft Word Document in DCOM Config – gbbosmiya Sep 06 '13 at 13:10
  • If you have MS Word installed, the CLSID should present. Remember, that `Microsoft Word Document` will be localized with your system language. Unfortunately DCOM Config doesn't allow to sort by CLSID, so finding by CLSID value is quite annoying thing. – Serge S. Sep 07 '13 at 13:05
8

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!
Michael Paulukonis
  • 9,020
  • 5
  • 48
  • 68
6

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".
gyosifov
  • 3,193
  • 4
  • 25
  • 41
5

This one was sticky for me to figure out, maybe my Windows mojo skills are just sub-par. But I could not get Component Services to run in 32 bit mode on Windows Server 2008. Hopefully this can help someone else with the same problem:

  1. Run Component Services by either method previously mentioned (Run box or Administrative Tools); close this program
  2. Paste "C:\Windows\System32\mmc.exe" /32 into the Run box and hit Enter (verify in Task Manager that you see mmc.exe *32)
  3. Go to File and you should see comexp.msc in the list (because of step 1), select it and it'll open Component Services in your 32 bit mode MMC console.

EDIT: just for completeness sake, in order to get Word Interop working on Windows Server 2008 I also had to create the Desktop folder as outlined in this answer.

Community
  • 1
  • 1
sliderhouserules
  • 3,415
  • 24
  • 32
2

Fix to Tomas answer, correct command on Windows Server 2k8 x64 is: "dcomcnfg /32" (slash instead of -)

Also I had to customize all security options by adding IIS_IUSRS with full rights to Lunch and Activation Permissions, Access Permissions and Configuration Permissions. And Interactive user in Identity tab as well. Then it worked for me.

I had this problem with Word 2010 opening doc files and I had to set it for Microsoft Word 97-2003 Document Properties.

Krissce
  • 21
  • 2
1

This error corresponds to .NET System.UnauthorizedAccessException and is usually caused by wrong settings for access on COM component your code tries to create.

You may try to start dcomcnfg utility, go to DCOM settings, select required object and allow access to it for the account your ASP.NET code runs under. It should solve your problem.

elder_george
  • 7,849
  • 24
  • 31
  • This is true, but if your running Windows 7 64bit, you have to start dcomcnfg as 32bit: "dcomcnfg -32". If you dont, you wont find the Word or Excel to set the permissions – Tomas I Aug 16 '10 at 08:07
0

I had the same problem, finally was because my user didn't have permission to run the service "Remote Procedure Call(RPC)". In control panel, Administrative tools, I looked for that service and in Log On I clicked in "Local System Account", I restarted the system and problem solved.

0

I test all above methods that also marked as answer but in windows server when user is not active or logoff, get access exception. so:

  1. I created a user on local computer and add it to two group: IIS_USER and Administrator
  2. Component Services -> Computers -> My Computer -> DCOM Config
  3. In com+ object i change to run Microsoft Word 97 – 2003 Document component with this user. See it here
  4. also add IIS_USER and also Application-identity user (IIS APPPool\[Name]) to all three section on security section and make the full permission as possible. See it here

office will run with settings from user that you create in first step, so if you change any setting with this user. 120% Working with no problem. tried over 3 different server.

Mahdi
  • 649
  • 8
  • 18
0

Go to registry HKCR>TypeLib>{00020905-0000-0000-C000-000000000046}>8.7>0, then delete the folder "win32" this is for Word COM Class error.

Go to registry HKCR>TypeLib>{00020813-0000-0000-C000-000000000046}>1.9>0, then delete the folder "win32" this is for Excel COM Class error.

Try that method that method fixed my problem.

sanjeev
  • 1,664
  • 19
  • 35
0

I created the folder C:\Windows\System32\config\systemprofile\desktop , that fixed my problem that my Service couldn't open Excel files.

martin
  • 1