Outlook 异常代码:0xc0000005 Visual studio C#

Outlook Exception code : 0xc0000005 Visual studio C#

我开发了一个应用程序,允许您从 Outlook 邮箱的电子邮件中恢复文件。

为了帮助我完成这项任务,我使用了 Interop.Microsoft.Office.Interop.Outlook 库。

我们在 Windows 2012 R2 服务器上使用这个可执行文件。 当我 运行 它手动时它完美地工作。但是,当我使用 Windows 创建计划任务时,出现此错误:

Faulting application name: OUTLOOK.EXE, version: 16.0.5071.1000, time stamp: 0x5f629f8a
Faulting module name: mso30win32client.dll, version: 16.0.5080.1000, time stamp: 0x5f7cb315
Exception code: 0xc0000005
Fault offset: 0x0008ecda
Faulting process id: 0x474c
Faulting application start time: 0x01d6c9690e7c78aa
Faulting application path: C:\Program Files (x86)\Microsoft Office\Office16\OUTLOOK.EXE
Faulting module path: C:\Program Files (x86)\Common Files\Microsoft Shared\Office16\mso30win32client.dll
Report Id: 4c375292-355c-11eb-80d7-005056ac1822
Faulting package full name: 
Faulting package-relative application ID: 

然后我有这个错误:

Application: DepotMailMcp.exe
CoreCLR Version: 4.700.20.41105
.NET Core Version: 3.1.8
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
   at DepotMailMcp.Program.ProcessMail(String email, String lastMail, XmlNode actualNode) in C:\Users\Florian\Documents\Gitlab\DepotMCP\DepotMailMcp\DepotMailMcp\Program.cs:line 147
   at DepotMailMcp.Program.LaunchApp() in C:\Users\Florian\Documents\Gitlab\DepotMCP\DepotMailMcp\DepotMailMcp\Program.cs:line 121
   at DepotMailMcp.Program.Main(String[] args) in C:\Users\Florian\Documents\Gitlab\DepotMCP\DepotMailMcp\DepotMailMcp\Program.cs:line 46

在我程序的第 147 行,我有这个:

Application appOutlook = new Application();

我终于得到了最后一个错误:

Faulting application name: DepotMailMcp.exe, version: 1.0.0.0, time stamp: 0x5f3ed60d
Faulting module name: KERNELBASE.dll, version: 6.3.9600.19724, time stamp: 0x5ec50c3e
Exception code: 0xe0434352
Fault offset: 0x000156e8
Faulting process id: 0x3e80
Faulting application start time: 0x01d6c9690e58b558
Faulting application path: C:\Applications_MCP\Mail_Depot\Application\DepotMailMcp.exe
Faulting module path: C:\Windows\SYSTEM32\KERNELBASE.dll
Report Id: 5e785666-355c-11eb-80d7-005056ac1822
Faulting package full name: 
Faulting package-relative application ID: 

我已将计划任务配置为在与手册中相同的用户上启动,我尝试在 运行 中以最高权限启动它 但没有任何效果。

你有办法解决我的问题吗?

ps: 我们使用 Outlook 2016

一般的 Office 应用程序,尤其是 Outlook,不能 运行 在服务中(例如 Windows 调度程序)。

您需要使用 EWS (in case of Exchange Server), Extended MAPI (C++ or Delphi only), or Redemption (any language, its RDO 对象系列是一个 MAPI 包装器 - 我是它的作者)。