Outlook Exception code : 0xc0000005 Visual studio C#

-1

I developed an application that allows you to recover files from emails from an Outlook mailbox.

To help me in this task, I use the Interop.Microsoft.Office.Interop.Outlook library.

We are using this executable on a Windows 2012 R2 server. When I run it manually it works perfectly. However when I create a scheduled task using Windows I get this error:

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: 

I then have this error:

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

At my line 147 of my program I have this :

Application appOutlook = new Application();

And i get finally this last error:

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: 

I have configured the scheduled task to be launched on the same user as in manual and I tried to launch it in run with highest privileges but nothing works.

Do you have any idea to solve my problem?

ps: We use Outlook 2016

c#
outlook
asked on Stack Overflow Dec 3, 2020 by Biscotto • edited Dec 3, 2020 by Uwe Keim

1 Answer

2

Office apps in general, and Outlook in particular, cannot run in a service (such as the Windows Scheduler).

Yo would need to use EWS (in case of Exchange Server), Extended MAPI (C++ or Delphi only), or Redemption (any language, its RDO family of objects is a MAPI wrapper).


User contributions licensed under CC BY-SA 3.0