VSTO Outlook 2007 外接程序启动抛出 System.Runtime.InteropServices.COMException (0x80020009):无法完成操作。您尚未连接

发布于 2024-12-01 02:31:26 字数 1202 浏览 1 评论 0原文

我们正在使用 VSTO 构建 Outlook 2007 加载项。我们在插件的初始化逻辑中有代码,用于检索与 Application.Session 关联的 MAPIOBJECT。有问题的代码如下:

public partial class ThisAddIn
{
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        try
        {
            var addIn = Globals.ThisAddIn;
            var application = addIn.Application;
            var mapiObject = application.Session.MAPIOBJECT;
        }
        catch (Exception e)
        {
            // HANDLE ERROR
        }
    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
                        // ...
    }

    // Other VSTO generated code

}

这段代码在大多数情况下都非常有效。但是,当我们尝试从 Session 属性访问 MAPIOBJECT 属性时,我们会遇到以下错误:

System.Runtime.InteropServices.COMException (0x86220009): Cannot complete the operation. You are not connected.
  at Microsoft.Office.Interop.Outlook._NameSpace.get_MAPIOBJECT()
  at MyTestAddIn.ThisAddIn.ThisAddIn_Startup(object, System.EventArgs) in C:\foo\MyTestAddIn\ThisAddIn.cs:line 19

我们无法理解为什么代码大部分时间都有效,但有时会失败。我们认为此问题是由于网络中断/用户离线工作造成的。我们尝试了多种连接状态组合,包括故意从 Outlook 脱机工作,以及在 Outlook 即将加载加载项时断开网络电缆。但我们还无法重现该问题。

任何帮助表示赞赏。

We are building an Outlook 2007 add-in using VSTO. We have code in the initialization logic of the addin which retrieves the MAPIOBJECT associated with the Application.Session. The code in question is as follows:

public partial class ThisAddIn
{
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        try
        {
            var addIn = Globals.ThisAddIn;
            var application = addIn.Application;
            var mapiObject = application.Session.MAPIOBJECT;
        }
        catch (Exception e)
        {
            // HANDLE ERROR
        }
    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
                        // ...
    }

    // Other VSTO generated code

}

This code works like a charm for most times. However, we run into the following error when we attempt to access the MAPIOBJECT property from the Session property:

System.Runtime.InteropServices.COMException (0x86220009): Cannot complete the operation. You are not connected.
  at Microsoft.Office.Interop.Outlook._NameSpace.get_MAPIOBJECT()
  at MyTestAddIn.ThisAddIn.ThisAddIn_Startup(object, System.EventArgs) in C:\foo\MyTestAddIn\ThisAddIn.cs:line 19

We are unable to understand why the code works most of the time but fails at a few. We thought this issue was due a network interruption/user working offline. We tried several combinations of connection states with intentionally working offline from Outlook to disconnecting the network cable when Outlook is about to load the add-in. But we have not been able to reproduce the problem.

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2024-12-08 02:31:26

这么早请求 MAPI 会话通常是个坏主意,因为它可能尚未正确登录。为什么不在您真正需要时请求会议呢?

It's usually a bad idea to ask for the MAPI session that early, because it might not be properly logged on yet. Why not ask for the session the moment you actually need it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文