管理调试助手'DisconnectedContext' [英] Managed Debugging Assistant 'DisconnectedContext'

查看:1913
本文介绍了管理调试助手'DisconnectedContext'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Unity创建一些COM对象的VS2105中设置单元测试后,我开始收到以下错误:

After setting up a unit test in VS2105 which created some COM objects using Unity I started getting the following error:

Managed Debugging Assistant' DisconnectedContext在C:\PROGRAM文件(X86)\MICROSOFT VISUAL STUDIO 14.0 \COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\te.processhost.managed.exe中检测到问题。 / code>

Managed Debugging Assistant 'DisconnectedContext' has detected a problem in 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\te.processhost.managed.exe'.

我快速查看是否有其他人遇到相同的问题,很多问题的解决方案是要么测试在它自己的线程或更改目标架构到x64。这些解决方案都没有对我感觉很对,因为他们更像是解决问题的工作。

I had a quick look to see if anyone else had the same problems and a lot of the solutions to the problem were either to fire off the test in it's own thread or change the target architecture to x64. Neither of these solutions felt quite right to me as they are more like work-arounds to the problem.

所以后不久想到我的问题是COM对象没有足够的时间通过测试框架来清除。所以我想出了以下解决方案工作。

So after little thought I realised the problem is that the COM objects are not being given enough time by the test framework to clear down. So I came up with the following solution which worked.

推荐答案

为了解决这个问题,我添加了下面的代码,测试清理方法的单元测试:

To fix the problem I added the following code to the tear down / test clean up method of the unit test:

_unity.Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();

第一行只需要使用Unity,但修复的主要部分是最后两行。他们强制垃圾收集,然后告诉当前线程等待,直到它完成。因此允许COM对象被正确清除。

The first line is only need if using Unity however the main part of fix is the last two lines. They force a garbage collection and then tell the current thread to wait until it has completed. Thus allowing the COM objects to be cleared down properly.

这篇关于管理调试助手'DisconnectedContext'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆