Excel 来自 Windows 的互操作 EXCEL.EXE 中的服务崩溃,版本:16.0.4966.1000,模块:oart.dll,版本:16.0.4900.1000

Excel Interop from Windows Service crash in EXCEL.EXE, Version: 16.0.4966.1000, Moduls: oart.dll, Version: 16.0.4900.1000

请不要发表评论,Windows 服务的互操作模式不受支持,我知道。 :-)

我有一个包含表格和图表的 Excel 文件。它在 Windows Server 2012R2 和 Excel 2003 作为 Windows 服务在互操作模式下运行了几年没有任何问题。

更改为 Windows Server 2019 和 Excel 2016 后,无法再使用以下代码打开此文件:

Application excelApp = new Application();
Workbooks  workBooks = excelApp.Workbooks;
workBook = workBooks.Open(<Path To Excel-File>, 0, false, 5,
     Missing.Value, Missing.Value, true, XlPlatform.xlWindows, "\t", true, false, 0, true);

它导致我的错误处理在:

System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception. 
(Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))

并且事件日志显示:

Name der fehlerhaften Anwendung: EXCEL.EXE, Version: 16.0.4966.1000, Zeitstempel: 0x5e205905
Name des fehlerhaften Moduls: oart.dll, Version: 16.0.4900.1000, Zeitstempel: 0x5d53033a
Ausnahmecode: 0xc0000005
Fehleroffset: 0x0006e67e
ID des fehlerhaften Prozesses: 0x1a38
Startzeit der fehlerhaften Anwendung: 0x01d5e64d380ea691
Pfad der fehlerhaften Anwendung: C:\Program Files (x86)\Microsoft Office\Office16\EXCEL.EXE
Pfad des fehlerhaften Moduls: C:\Program Files (x86)\Microsoft Office\Office16\oart.dll
Berichtskennung: b6eee871-9dca-4ddc-8d4b-cdd9f58f871b

在对我的文件进行数小时的测试后,我创建了一个新的 Excel 文件,打开它并向单元格读取或写入数据没有问题。比我从文件中删除越来越多的 table 和图表,最后我找到了崩溃原因:

是否有任何图表中有任何嵌入图像,或者 table 无法使用来自 Windows 服务的 Interop 打开文件。

使用命令行应用程序使用相同的代码打开文件(带有内部图像)从来没有问题。

但是可以将图像放在页眉或页脚中。没问题。 疯了。