Excel Automation through Windows Service written in C# fails in Office 365 installed machines

1

I am working with Windows Service written in C#. Through this Windows Service I am automating Excel in a programmatic way.

Excel.Application excel = Excel.Application();

This code was working fine with all versions of Excel (2003, 2007, 2010, 2013). Recently I have installed Office 365 in my machine. Suddenly I am getting below exception when I automate the Excel using above call:

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)).

Can anyone let me know, is there any special consideration should be taken when automating the Office 365 Excel via Windows Service?

c#
excel
vsto
office365
asked on Stack Overflow Sep 21, 2015 by S.Connery • edited Sep 21, 2015 by pnuts

1 Answer

1

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. Read more about that in the Considerations for server-side Automation of Office article.

You may consider using the Open XML SDK instead, see EWS Managed API, EWS, and web services in Exchange for more information. Or any third-party components designed for the server-side execution.

answered on Stack Overflow Sep 23, 2015 by Eugene Astafiev

User contributions licensed under CC BY-SA 3.0