Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook 2003 add-in - Getting COM exception on application shutdown after creating WPF window

I'm developing an outlook 2003 add-in. Until now I used only winforms to display one form, but today I've added a WPF window for more complex stuff. DUe to the WPF window, a COM exception is being thrown when outlook shuts down.

Does anybody know why? I need to start a separate thread for the WPF window in single apartment state.

Here is the exception:

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: 

Best Regards,
Oliver Hanappi

like image 322
Oliver Hanappi Avatar asked Nov 05 '22 14:11

Oliver Hanappi


1 Answers

You need to Invoke Shutdown on WPF window Dispatcher in the same thread after the window is closed.

window.Dispatcher.InvokeShutdown();

A similar problem was reported in Microsoft Connect

like image 187
Deepak N Avatar answered Nov 15 '22 11:11

Deepak N