您的位置:首页 > 其它

一个WPF程序UnitTest发生错误的解决办法

2011-05-17 15:16 260 查看
[TestMethod]
public void Test()
{
Window window = new Window();
window.Show();
window.Close();
window = null;
}


以上代码会引发一个异常,异常消息如下:

"An unhandled exception of type 'System.Runtime.InteropServices.InvalidComObjectException' occurred in PresentationCore.dll Additional information: COM object that has been separated from its underlying RCW cannot be used."

解决办法: 在TestCleanup()中调用CurrentDispatcher.InvokeShutdown() 。

[TestCleanup]
public void TestCleanup()
{
System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
}


参考: Tricks for Writing Unit Tests for WPF Applications
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐