Managed Debugging Assistant 'DisconnectedContext'

你说的曾经没有我的故事 提交于 2019-12-11 04:57:53

问题


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' has detected a problem in 'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\te.processhost.managed.exe'.

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.

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.


回答1:


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();

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.



来源:https://stackoverflow.com/questions/37787161/managed-debugging-assistant-disconnectedcontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!