Using COM Objects from ASP.NET

iStock_000005899630MediumI got the following question yesterday:

Hi, I created a web application in which I am generating a ms-word document using Microsoft.Office.Interop.Word dll. The application is running fine in the visual studio but when I tried to run on IIS 5.0 through virtual directory then its giving the following error – Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005. In my application I have taken reference of Microsoft Word 12.0 Object Library, but its coming as Microsoft.Office.Interop.Word dll, this interop dll is just a wrapper of the actual word COM dll. But I have to register the actual word COM dll. so my problem is to find – 1) The path of the original word dll(COM) 2) How to register this dll, either using regsvr32 or to register on IIS. OR there will be any other solution. I have gone through many forums but did’nt get any solution. If you have any idea/suggestion on COM Word components please revert me back.

First, you really shouldn’t be using COM from ASP.NET.  That’s not to say that you can’t, but there are so many issues when you do this that you are really better off avoiding it if at all possible. Find a third party dll that is written in .NET.

Second, I’d be willing to bet that when you developed this application, you developed it as a file based project instead of developing it under IIS.


You always want to develop your web applications under IIS so that you run into these types of problems while you are developing instead of after the fact.  If your operating system doesn’t have IIS available, upgrade to one that does!

The error message is telling you that you don’t have permission to run the COM object.  This was easily found using Google to search for the error code along with some possible solutions.

The problem is that ASP.NET is not running as a user that has access to the COM object.  In fact, ASP.NET can’t run any code outside of the virtual directory you created the application in by design.  You COULD grant the ASPNET_WP user access to the COM objects, but I would recommend against that for security reasons.

What I would recommend that you do instead is run Microsoft Word under COM+ as a specific user with rights to Word that can be accessed via COM+ remoting (even though it is all on the same computer) so that ASP.NET security isn’t compromised.

I did something similar when I wrote VSS.NET so that my web service could access the VSS COM DLL.  You can see a description of how I did this by checking out this article (see the section labeled, “COM+ vs ASPNET user”).

All of this assumes, of course, that you installed MS-Word on the IIS server and installed it so that everyone could run it so that the registry entries are visible to any user who is logged in on that computer.

Like this Article? Subscribe to get every article sent to your email.

Related Post

  • DotNetNuke Modules – Creating Base ModulesDotNetNuke Modules – Creating Base Modules Now that we have DotNetNuke installed into Visual Studio we can go ahead and create our first modules. Actually, creating the modules is pretty simple. But it is even easier to do it […]
  • The Case Against Location: File SystemThe Case Against Location: File System See this picture? That’s what could happen to your application if you decide to build your ASP.NET web site using the File System location instead of the HTTP location. To illustrate, […]
  • Compiler Error Message: CS0016Compiler Error Message: CS0016 Last Thursday I was working with a client trying to get some code I had written running under his copy of IIS on Windows Vista. The full text of the message indicates that the .NET […]
  • Getting started with jQuery and ASP.NETGetting started with jQuery and ASP.NET As promised, I am starting a series on jQuery.  Today our goal is to get a project setup in Visual Studio that uses jQuery.  We won't be explaining much in the way of syntax, but we will […]
  • Dave’s Top Programming ResourcesDave’s Top Programming Resources This isn't going to be a top ten list.  I don't think I have ten programming resources that I use on a regular basis.  Instead let's just call this Dave's Top Programming […]

About Dave Bush

Dave Bush is a .NET programmer and Certified ScrumMaster who is passionate about managing risk as it relates to developing software. When he is not writing or speaking about topics related to Application Lifecycle Risk Management (ALRM), he is an example to his peers as he develops web sites in the ASP.NET environment using industry best practices.

One Pingback/Trackback

Awards & Certs