4

I am trying to create xlsx file using microsoft.office.interop.excel.

When I run the web application in VS with IIS express it works prfectly, but when I run it in VS with local IIS I get:

{"Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))."}

I get the same exception on my server, server version: windows server 2016, IIS version: 10.0.14393.0

Note: DCOMC config contain Microsoft Excel Application.

Dale K
  • 25,246
  • 15
  • 42
  • 71
nel siboni
  • 41
  • 1
  • 3
  • 2
    There are slight differences in how IIS express works compared to IIS. IIS Express is more lax in terms of security due to development requirements. You can switch to using full IIS in your VS configuration (for the web project) and check if it works then. If not, try running the VS as an administrator, if it still doesn't work then check how your IIS is configured. Hope this helps. – Toni Kostelac Mar 14 '18 at 10:02
  • Microsoft Interop stuff doesn't like running as a system user. It makes it painful to run stuff that interacts with microsoft as a service and IIS might be trying to run it as a system user as well. – TheEvilMetal Mar 14 '18 at 10:38
  • Server side Office automation is doomed. There are also other things Microsoft won't support, https://blog.lextudio.com/the-most-common-technologies-not-supported-by-microsoft-8675c409bde2 – Lex Li Mar 14 '18 at 22:11
  • Dude, don't close a question and post a link to your blog as truth. It is not correct and don't give you more authority in your answer. – User.Anonymous Apr 05 '19 at 09:08

1 Answers1

2

When you execute IIS Express, the pool use your windows account, that have the right to access and launch Excel.

By default, local IIS use ApplicationPoolIdentity, so if you want execute external assembly, the best way is to change identity of pool by your windows account (or account created for this usage).

enter image description here

User.Anonymous
  • 1,719
  • 1
  • 28
  • 51
  • Though this answer explains why the app works on IIS Express, its advice to change IIS configuration is pointless. Microsoft does not support server side Office automation at all. – Lex Li Mar 14 '18 at 22:12
  • I've worked with this COM several years ago. Maybe now it is not possible, but it was possible on .Net2.0. This is not a good practices because each call to use this launch an excel.exe process. Process that should be disposed when the context is gone. This solution has many memory leak too. – User.Anonymous Mar 15 '18 at 12:14
  • Thanks to all responders. I worked it out by building new function using EPPlus. – nel siboni Mar 20 '18 at 10:44