I have a unit test project inside my solution. I keep adding new unit tests and modifying old ones. Some days ago, a message box keeps appearing when running my unit test project. The message box say:
DisconnectedContext was detected Message: Context 0x2aae50' is disconnected. Releasing the interfaces from the current context (context 0x2aad98).This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the applicationis completely done with the RuntimeCallableWrappers that represent COM components that liveinside them.
If I press 'OK' the unit test run is cancelled, if I press 'Continue' the tests are run as expected. The tests are not affected by this error (at least I don't think so), but it is very annoying. It used to work ok, so I don't if there is something I changed on the solution or project.
I checked information in MSDN about this error and it said it is caused by:
The OLE apartment or context has been shut down when the CLR attempts to transition into it. This is most commonly caused by STA apartments being shut down before all the COM components owned by the apartment were completely released This can occur as a result of an explicit call from user code on an RCW or while the CLR itself is manipulating the COM component, for example when the CLR is releasing the COM component when the associated RCW has been garbage collected.
And the resolution is:
To avoid this problem, ensure the thread that owns the STA does not terminate before the application has finished with all the objects that live in the apartment. The same applies to contexts; ensure contexts are not shut down before the application is completely finished with any COM components that live inside the context.
Based on this explanation (which honestly I don't fully understand) I have not idea why this is happening when running my Unit Test project.
So the question is How I could get rid of this error?