80080005 使用 Word Automation 时服务器执行失败

80080005 Server execution failed when using Word Automation

我有一个处理 Word 文档的 .Net C# 应用程序。

我正在使用 Microsoft.Office.Interop.Word.dll,Office 2010 的一部分,产品版本 14。0.xxx。正在调用:

using Microsoft.Office.Interop.Word;

...

Application app = new Application();

导致以下错误:

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

我还注意到,当生成此错误时,会创建并挂起 WINWORD.EXE 的实例,但该文件关联到 Office 365,产品版本 16.0.xxx.

我假设错误的(至少一个)来源是我正在使用的 .dll 与我的开发计算机上安装的 Word 版本之间的不兼容。

问题

是否可以在服务器上不安装 Microsoft Office 的情况下执行办公自动化?

您无需在服务器上安装 MS 即可使用办公自动化!

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.

Is it possible to perform office automation without having Microsoft Office installed on the server?

不,这是不可能的。相反,如果您只处理打开的 XML 文档,您可以考虑使用 Open XML SDK。否则,您可以考虑使用任何专为服务器端执行而设计的第三方组件,例如 Aspose。

Considerations for server-side Automation of Office 文章陈述如下:

All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended.

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.