C# 和 Outlook 之间的异常

NES*_*HOM 1 c# outlook exception

我有一个简单的代码可以使用 C# 在 Outlook 2013 中打开撰写电子邮件。当 Outlook 未运行时,它可以正常工作,但当 Outlook 已经打开时,我收到此异常:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
Run Code Online (Sandbox Code Playgroud)

这是我的简单代码:

        Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
        Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
        mailItem.Subject = "This is the subject";
        mailItem.To = "someone@example.com";
        mailItem.Body = "This is the message.";
        mailItem.Display(true);
Run Code Online (Sandbox Code Playgroud)

我也从 Visual Studio 输出窗口得到这些抱怨我不知道的符号!:

Additional information: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
'mCPanel.vshost.exe' (CLR v4.0.30319: mCPanel.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Outlook\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Outlook.dll'. Module was built without symbols.
'mCPanel.vshost.exe' (CLR v4.0.30319: mCPanel.vshost.exe): Loaded 'C:\Windows\assembly\GAC_MSIL\office\15.0.0.0__71e9bce111e9429c\office.dll'. Module was built without symbols.
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏?提前致谢

Dmi*_*nko 5

这很可能是由安全上下文的差异引起的。Outlook 或您的应用程序是否以提升的权限运行?