3
当使用MSTest进行单元测试时,我创建了一个WPF窗口。当该窗口关闭时,Visual Studio显示InvalidComObjectException
:为什么在单元测试中创建的关闭窗口会引发InvalidComObjectException?
COM object that has been separated from its underlying RCW cannot be used.
它之后的[TestMethod]
退出凸起,堆栈仅包含外部码(没有InnerException
)。这是我有:
StackTrace:
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)
DeclaringType:
{Name = "TextServicesContext" FullName = "System.Windows.Input.TextServicesContext"}
Assembly:
{PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35}
这是创建窗口中的代码:
var myWindow = new SomeWindow(errors);
myWindow.ShowDialog();
该窗口包含两个ListView
s的一些文本元素,并在其中
太棒了!谢谢!这是MSTest简单的解决方案:'[TestCleanup] public void Cleanup(){Dispatcher.CurrentDispatcher.InvokeShutdown(); }' – Tar