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

10

50

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.

Yellowgreen answered 27/2, 2014 at 7:52 Comment(6)
I know it seems silly, but have you got excel correctly installed on the server?Antihistamine
Yes, I have Excel installed on the server.Yellowgreen
We've started to use Gembox instead of Microsoft.Office.Interop.Excel. This library does not require an Office installation server-side.Yellowgreen
Try this one, it was helpfull for me [post][1] [1]: https://mcmap.net/q/102796/-system-unauthorizedaccessexception-retrieving-the-com-class-factory-for-word-interop-fails-with-error-80070005Prothonotary
For me only setting the IIS user as "this user" under DCOM | Properties | Identity tab worked.Touch
What anti-virus software do you use on the host?Burdette
F
33

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.

Fireside answered 27/9, 2016 at 12:43 Comment(3)
This only works when user is logged into the server.Importunity
what if there is no Microsoft Excel Application entry in that path?Splat
Same as @Splat I don't see Microsoft Excel Application entry in the path. Also does this only works when user is logged in?Madiemadigan
Z
13

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);
Zworykin answered 11/3, 2019 at 10:23 Comment(1)
I used to solve the same exact problem while trying to interact with MapPoint InteropSouthern
C
8

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/

Campagna answered 1/2, 2018 at 12:1 Comment(2)
A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. Answers that are little more than a link may be deleted.Villar
@paper1111 I've edited my answer why down vote give enough time to improve the answer While I welcome your suggestion I am working on similar issue and found this directly from Microsoft technical support about this issue If someone mark the answer down Users would not give importance to the answer or link shared in answer.Campagna
A
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

Accrual answered 24/6, 2018 at 10:54 Comment(0)
W
2

The fix for me is to disable AutoRecover from File -> Options -> Save, then discard all autorecovered files. It would appear it's the volume of autorecover files which is the root cause.

Background I cycle through a lot open / close /compute cycles. Periodically the C# app fails to open a workbook with the below 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)).

The app repeatedly throws this error and is stuck in this state until the AutoRecovered files are cleared from Excel.

Another symptom follows; when I try to open Excel app (as if to create a new workbook, not open an existing one), it takes a long time spinning cpu cycles. It opens eventually and there are tons of files listed in the Recovered files pane on the left.

I Close the pane using the button, all the files are then discarded. Re-opening Excel again after this procedure is near instant. The app runs fine again from hereon.

Washwoman answered 2/9, 2021 at 23:41 Comment(1)
This was also the cause in my case. Actually, I resolved it by opening Excel, seeing many hundred files listed in the Recovery tab, clicking "Close" on the recovery tab, which deleted all the files, then closing Excel. Next time I tried using interop, the error no longer occured.Auld
M
0

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

Minnaminnaminnie answered 10/6, 2014 at 14:3 Comment(0)
M
0

Start -> Run (Windows+R)

Type: dcomcnfg -32 (hit enter) this should open Component Services

Expand Component Services, Computers, My Computer, DCOM Config

Scroll down to "Microsoft Excel Application"

Right Click, select properties, go to Security tab

Edit Access Permissions

Click Add

Type <Computer_Name>/IIS_IUSRS (or go to Locations, select computer name - if using domain, by default, it will search the domain and will not find IIS_IUSRS)

Make sure the check box for "Allow" is checked for "Local Access"

Click OK, Click OK again (no rebooting is necessary)

Windows Update will reset this ever single time

Mimir answered 14/12, 2021 at 12:58 Comment(0)
S
0

I had a similar issue with my Visual Studio Console Application. I have tried the above solution mentioned by "Vladimir Shiyanov".

Apart from that my application was set to run only for 32-bit applications, When I unchecked that, the application ran successfully.

Shamrao answered 1/9, 2023 at 15:9 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Unwrap
M
0

I tried all of this, nothing worked. For me it was just opening Excel that made it work, then close it. Just that, opening it and close it.I really do not understand WHY it just happened to be that. Tried twice, both same error, both solved by just opening Excel.

Mauldon answered 14/11, 2023 at 19:17 Comment(0)
R
-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.

Roadside answered 8/5, 2016 at 15:15 Comment(1)
There are not callback functions available for open and save Excel files. I was having issue to save file. MS support team provided me a hint of adding sleep after save. It works for me.Roadside

© 2022 - 2024 — McMap. All rights reserved.