代码之家  ›  专栏  ›  技术社区  ›  Oliver Hanappi

Outlook 2003加载项-在创建WPF窗口后关闭应用程序时获取COM异常

  •  5
  • Oliver Hanappi  · 技术社区  · 15 年前

    我正在开发outlook 2003外接程序。到目前为止,我只使用winforms来显示一个表单,但今天我添加了一个WPF窗口来显示更复杂的内容。由于WPF窗口的原因,当outlook关闭时将引发COM异常。

    有人知道为什么吗?我需要在单单元状态下为WPF窗口启动一个单独的线程。

    以下是例外情况:

    System.Runtime.InteropServices.InvalidComObjectException was unhandled
      Message="COM object that has been separated from its underlying RCW cannot be used."
      Source="PresentationCore"
      StackTrace:
           at System.Windows.Input.TextServicesContext.StopTransitoryExtension()
           at System.Windows.Input.TextServicesContext.Uninitialize(Boolean appDomainShutdown)
           at System.Windows.Input.TextServicesContext.TextServicesContextShutDownListener.OnShutDown(Object target)
           at MS.Internal.ShutDownListener.HandleShutDown(Object sender, EventArgs e)
      InnerException: 
    

    谨致问候,

    1 回复  |  直到 14 年前
        1
  •  2
  •   Andrew Grimm atk    14 年前

    在窗口关闭后,您需要在同一线程中调用WPF窗口调度程序上的Shutdown。

    window.Dispatcher.InvokeShutdown();
    

    报告了一个类似的问题 Microsoft Connect