【问题标题】:MailItem.HtmlBody throws a Not Implemented exceptionMailItem.HtmlBody 抛出未实现的异常
【发布时间】:2016-06-21 13:48:31
【问题描述】:

我有一个功能区按钮,通过根据其中的收件人修改 MailItem 对象,将文本插入到 Outlook Inspector 中。点击时调用的方法如下所示:

public async void OnTemplateClick(Office.IRibbonControl control)
        {
            var templateId = control.Tag;
            var template = templates.GetTemplateById(templateId);
            await templateUi.SetTemplate(control.Context, template);
        }

SetTemplate 方法如下所示:

public async Task SetTemplate(object window, Template template, 
            SynchronizationContext uiThread = null)
{
Outlook.MailItem currentMailItem = null;
            Outlook.Recipients olRecps = null;
            Outlook.Recipient recp = null;
            Outlook.AddressEntry addEntry = null;
            try
            {
                currentMailItem = GetMailItem(window);
                olRecps = currentMailItem.Recipients;
                var recipType = Outlook.OlMailRecipientType.olTo;
                var recps = from r in olRecps.Cast<Outlook.Recipient>()
                            where r.Type == (int)recipType
                            select r;
                var numRecps = recps.Count();

                var oldBodyHtml = currentMailItem.HTMLBody;
               ...

现在,有时,获取 HTMLBody 的最后一行会引发以下错误:

System.Runtime.InteropServices.COMException (0x8E604001): Not implemented.
   at Microsoft.Office.Interop.Outlook._MailItem.get_HTMLBody()

这个错误不会一直发生,而且很难重现,所以我们大多在应用程序日志中看到它。我想知道什么可能导致这个错误?我认为这与此异步调用的时间有关,这意味着 MailItem 消息没有完全形成?

谢谢!

【问题讨论】:

    标签: c# outlook vsto outlook-addin mailitem


    【解决方案1】:

    Outlook 对象模型不能用于辅助线程。 Outlook 2016 将在检测到此类调用时立即引发错误。在旧版本的 Outlook 中,调用可能会意外失败。

    如果必须使用辅助线程,您唯一的选择是 Extended MAPI(C++ 或 Delphi)或 Redemption(它的 RDO 对象系列 can be used on secondary threads)。

    【讨论】:

    • 当然,不要使用 async/await。
    猜你喜欢
    • 1970-01-01
    • 2015-06-03
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多