【发布时间】:2014-05-09 12:32:48
【问题描述】:
使用 Outlook 2010,调试时出现此错误
无法转换 COM 类型的对象 'Microsoft.Office.Interop.Outlook.ApplicationClass' 到接口类型 'Microsoft.Office.Interop.Outlook._Application'。此操作失败 因为 COM 组件上的 QueryInterface 调用
public void sendEMailThroughOUTLOOK()
{
try
{
String address = "john.doe@contoso.com";
Outlook.Application oApp = new Outlook.Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); // CRASHING HERE
oMailItem.To = address;
oMailItem.Subject = "Status Update on " + DateTime.Now.ToString("M/d/yyyy");
oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
oMailItem.Body = createEmailBody();
// body, bcc etc...
oMailItem.Display(true);
}//end of try block
catch (Exception ex)
{
Console.WriteLine(ex.InnerException.ToString());
}//end of catch
}
此代码在 Outlook 2013 上完美运行。但是在使用 Outlook 2010 时它不断崩溃。
我将 Interop.Outlook 从 15 降级到 14
【问题讨论】:
-
看看这个thread,它可能会有所帮助。
-
@kelix 引用站点上的代码是 VB.Net。答案是指 Office 安装损坏,但我知道我的 Office 没有损坏,因为它是全新安装。
标签: c# outlook interop office-interop