【问题标题】:Outlook Exception that doesn't make sense没有意义的 Outlook 异常
【发布时间】: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


【解决方案1】:

我认为你需要替换这个:

Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

用这个:

Outlook.MailItem oMailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem);

此外,如果此代码在加载项中,则无需创建 Outlook.Application 的新实例 - 使用传递给 OnConnection 事件的对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 2012-04-02
    • 2020-09-27
    • 2017-05-19
    相关资源
    最近更新 更多