一个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
相关文章推荐
- 创建ASP.NET程序时候发生错误"HTTP/1.0500ServerError"的一个解决办法
- 创建ASP.NET程序时候发生错误"HTTP/1.0 500 Server Error"的一个解决办法
- ORA-04063和ORA-06508两个Oracle程序错误的一个解决办法
- 安装Windows SDK7.1时发生的一个错误(附解决办法)
- win7安装oracle 10g时发生“程序异常终止。发生内部错误”的提示 解决办法
- 安装Windows SDK7.1时发生的一个错误(附解决办法)
- 安装Windows SDK7.1时发生的一个错误(附解决办法)
- 在windows2003server上运行asp程序,发生验证码看不到,文件找不到等错误的解决办法
- VS2013新建项目时出现的“发生一个或多个错误”的错误弹出问题解决办法
- Win7系统安装office2007时出现“错误1046,安装程序无法将值写入注册表”解决办法
- 程序安装时几种有错误提示的解决办法
- 彻底禁止Microsoft Security Client OOBE 程序错误解决办法 (关闭Windows Defender)
- caffe---make发生的错误和解决办法1
- Linux下安装MyEclipse和Tomcat服务器详解,以及我安装过程中所出现的问题以及解决办法,并实现一个web小程序
- 解决VC2005程序的一个运行错误“由于应用程序的配置不正确,应用程序未能启动"
- SQL Server安装问题程序被挂起的错误解决办法
- 启动Pro/TOOLKIT程序的常见错误及解决办法
- IIS未找到提供程序该程序可能未正确安装错误解决办法
- 延迟加载时发生no session错误的解决办法
- Android问题集锦之八:调用其他程序中的activity和Permission Denial: starting Intent 错误解决办法