I recently encountered a problem when I ran unit tests for my WPF windows. I got this error:
One of the background threads threw exception:
System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
at System.Windows.Input.TextServicesContext.StopTransitoryExtension()
at System.Windows.Input.TextServicesContext.Uninitialize(Boolean appDomainShutdown)
at System.Windows.Input.TextServicesContext.TextServicesContextShutDownListener.OnShutDown(Object target, Object sender, EventArgs e)
at MS.Internal.ShutDownListener.HandleShutDown(Object sender, EventArgs e)
To fix this error, add the following method to the class containing your tests:
C#
[TestCleanup]
public void CleanUp()
{
Dispatcher.CurrentDispatcher.InvokeShutdown();
}
With this fix, the error no longer occurs. Here is the link to the original solution: http://connect.microsoft.com/VisualStudio/feedback/details/318333/unit-tests-which-show-windows-cause-vstesthost-mstest-shutdown-crashes-in-vs-2008-rtm
Do you have a question or a suggestion about this post? Contact me!