Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))

41

I am trying to convert a .xls file to an .xlsx file on the server-side using Microsoft.Office.Interop.Excel.Workbook class as follows:

 workBook.SaveAs("FILENAME_HERE", XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

and I get the following error:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). : System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
   at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
   at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
   at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at CALLING_METHOD_IN_MY_LIBRARY_HERE...

The problem is that this error occurs only on the staging server; on my local machine it works fine.

Things that I have tried on the staging server:

  1. **1) Run dcomcnfg open Component Services

2) Expand Component Services "->" Computer "->" My Computer "->" the DCOM configuration "

3) Find the "Microsoft Excel application."

4) Right to open the Properties dialog box

5) Clicked on the "Security" tab,

6) "Launch and Activation Permissions, configure permissions, have added permissions - Identity run under Adminstrator user (This User), Interactive User and Launching Users

7). Launch and activation permissions + Access Permissions + Configuration Permissions => added IIS_IUSRS + Network Service with Full Controll**

2. Changed the build of the project that converts the .xls file from "Any CPU" to "x86" on my local machine and published this library on the server.

Did someone figured out how to fix this problem? I am struggling on fix this issue for 2 days now.

c#
excel
interop
xls
excel-interop
asked on Stack Overflow Feb 27, 2014 by Tamas Ionut • edited Nov 5, 2019 by Koby Douek

6 Answers

32

Using DCOMCNFG.exe. Open it and go to: Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application.

Open the properties, select Identity tab and select the interactive user.

answered on Stack Overflow Sep 27, 2016 by Vladimir Shiyanov • edited Sep 27, 2016 by m00am
12

I found the solution elsewhere.

Doing the following did solve my problem:

Using DCOMCNFG.exe. Open it and go to: Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application. Open the properties, select Identity tab and select the interactive user.

BUT - the problem came back every few minutes !

After hours of trying to figure out the cause, I noticed my server had hundreds of opened WINWORD.EXE processes. This caused a memory issue which leaded to the exception from hresult 0x80080005 error.

Well, stupidly enough, I forgot to write the code to close the interop application. Once I fixed that, the error was gone.

doc.Close(false);
Marshal.ReleaseComObject(doc);
word.Quit();
Marshal.ReleaseComObject(word);
answered on Stack Overflow Mar 11, 2019 by Koby Douek
6

I found this article which talks more about this issue in depth If this helps, error “80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))” could occur due to following reasons:

  1. The machine has a high CPU load and the process takes a long time to start and fails to execute the CoRegisterClassObjects() in less than 120 seconds.
  2. The COM server doesn't register for the right class IDs.
  3. The COM server is currently stopping and there is a race condition between CoCreateInstance and the COM server stopping part.
  4. There is a security problem in the way the COM server is started (this page seems to suggest misspelled passwords or lacking the "Login as Batch Job" privilege for "Run As.." COM servers, but anyway I would suggest re-verifying this information for your specific configuration)

https://blogs.msdn.microsoft.com/adioltean/2005/06/24/when-cocreateinstance-returns-0x80080005-co_e_server_exec_failure/

answered on Stack Overflow Feb 1, 2018 by ChiragMM • edited Feb 1, 2018 by ChiragMM
3

I fixed this issue with this solution: right click on Component Services/Computers/DCOM Config/Microsoft Word97 - 2003 Document properties/General Tab

set Authentication Level:None

answered on Stack Overflow Jun 24, 2018 by Ghadir Farzaneh
0

Same problem was solved for me by "allowing desktop interaction" for the service. (in tomcat6w config tool on Log On tab)

answered on Stack Overflow Jun 10, 2014 by Gabor
-4

Try to add Thread.Sleep Method, such as Thread.Sleep(2000) for 2 seconds after workBook.open and workBook.SaveAs two methods. If your Excel file has a lot of formats, try to extend few more seconds.

answered on Stack Overflow May 8, 2016 by Robert 30005

User contributions licensed under CC BY-SA 3.0