Using Interop Library for Web Server Side Excel Creation

3

I am trying to create excel files using interop library, but below is the error I get:

Creating an instance of the COM component with CLSID {00024500-0000-0000-
C000-000000000046} from the IClassFactory failed due to the following error: 8001010a 
The message filter indicated that the application is busy. 
(Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)). 

I looked into lots of resources out there on the net, which broadly can be categorized into following:

  1. Interop libraries are specifically built for desktop applications, and using them in a server side web application such as wcf is highly not recommended.
  2. Permission issues related to interactive user or DefaultAppPool.

so and and so forth.

Well, here's the caveat, I cannot change the server side application and everything works everywhere else. Few days ago, office 2016 got pushed on my machine from IT, and things stopped working (with above error) on my local machine. Now I can't go and change a legacy code, but see if I can fix the issues on my local to do further development.

Here's what I did, please note that everything was working on this machine (when office 2013 was there):

  1. Got office 2016 Uninstalled, and re-installed office 2013, same issue, hence reverted back to office 2016. Currently MS-Office 2016 32 Bit is installed.
  2. Verified permissions on various sections of security tab of Microsoft Excel Application, have added IIS AppPool\DefaultAppPool user, IIS_IUSRS, Interactive User with full control permission, (shouldn't the error be "Access denied", had permissions been wrong?)
  3. Created a new sample web application, to quickly debug, ran it in all combinations of cpu platform i.e. x86, AnyCpu, x64 - same issue.
  4. Interestingly enough, it works if I point my sample application to IIS Express instead of Local IIS.
  5. Added latest version of interop assembly available (Install-Package Microsoft.Office.Interop.Excel -Version 15.0.4795.1000) - still same issue
  6. Added Microsoft Office 16.0 Object Library (2.8) to the project - still same issue

It's an age old question and its probably better to get away with interop, but I wanted to understand what might be going wrong - all the direct results for the error above suggest implementing IMessageFilter or what not, but I cannot change server side code, below line should simply work as it used to few days ago:

Microsoft.Office.Interop.Excel.Application l_ExcelApp = 
new Microsoft.Office.Interop.Excel.Application();

but it doesn't, so what changed? what might have gone wrong?

Also, if it helps - ApplicationID listed in dcomcnfg (/32) is : 00020812-0000-0000-C000-000000000046}, but error has a different one.

Where to look? I hope answer to this question can guide lost souls for ever about this issue.

c#
excel
office-interop
excel-interop
asked on Stack Overflow Oct 4, 2017 by Manish Mishra

2 Answers

0

I'd recommend using the Open XML SDK for dealing or generating open XML documents on the server-side, see Welcome to the Open XML SDK 2.5 for Office for more information. Or just use any third-party components designed for the server-side execution.

As you already noticed, the Considerations for server-side Automation of Office article states the following:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

answered on Stack Overflow Oct 7, 2017 by Eugene Astafiev
0

Finally I was able to resolve my issue. Following works:

Web Application hosted in IIS, creating excel documents.

So it turns out, apart from the permissions, it is also very important that the application architecture should be similar i.e. my application was 64bit (running as Any CPU on 64bit OS). Whenever you run into such an issue, make sure following also (apart from setting right permissions to right user):

  1. Make sure the architecture of the two applications i.e. (your own and excel) are in sync. One quick way to know whether your excel is 64bit or 32 bit is by looking into Task Manager running programs. If excel is listed as EXECEL.EXE*32 then your office is 32 bit.
  2. When you install a new version of excel, make sure you completely remove previous versions (and not just uninstall, but also removal of dcomconfig office entries i.e. by deleting any registry entry you can find in regedit for the involved office applications guid, specially excel).

  3. I made it work by removing Office 2016 completely as described in 2, afterwards installing Office 2013 and fixing Microsoft.Office.Core reference accordingly in my code.

  4. Permissions that I assigned was following: Application Identity - Interactive User And inside Security tab, added IIS AppPool\DefaultAppPool user to all sections and gave full permission.
  5. My app runs in ApplicationPoolIdentity inside IIS.

If doing all the above, still doesn't fix your problem, then God be with you, and more power to you for your journey towards open XML.

answered on Stack Overflow Oct 8, 2017 by Manish Mishra

User contributions licensed under CC BY-SA 3.0