C#和Outlook之间出现异常

本文关键字:异常 之间 Outlook | 更新日期: 2023-09-27 18:28:11

我有一个简单的代码,可以在Outlook 2013中使用C#打开一封撰写电子邮件。当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)).

这是我的简单代码:

        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);

我还从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)).

有什么需要帮忙的吗?提前感谢

C#和Outlook之间出现异常

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