Managed Debugging Assistant 'DisconnectedContext' has detected a problem

Oct 18, 2011 at 3:12 AM
Edited Oct 18, 2011 at 3:14 AM

Hi all,

Visual Studio often shows this error ever since I added ManagedUPnP to my project. Is this error normal?

Managed Debugging Assistant 'DisconnectedContext' has detected a problem in 'D:\Projects\project1\bin\Debug\project1.vshost.exe'.

Additional Information: Context 0x2136e8' is disconnected. Releasing the interfaces from the current context (context 0x212e48). This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the application is completely done with the RuntimeCallableWrappers that represent COM components that live inside them.

When this error occurs, Visual Studio will have focus and let me choose between "Break" and "Continue".

If I click "Break", there is nothing much I can do, since no source code and disassembly are available for me to trace the error.

If I click "Continue", the program continues, but this error may occur again, the program seems running normally but I am worried :)

The same error occurs too to ManagedUPnPTest.

Thank you very much. Also thanks to thetoid for the reply of other post.

Coordinator
Oct 18, 2011 at 4:37 AM
Edited Oct 18, 2011 at 4:47 AM

Chloh,

Yes, this is normal, this error is a result of using the Microsoft UPnP COMObjects under an Multi Threaded apartment environment, its due to the COM implementation not fully supporting MTA applications, it will not cause any problems and will not error  unless debugging in the IDE, you can disable the warning from showing while debugging by disabling the respective Debugging Assistant MDA notification with in Visual Studio by doing the following:

 

1) In the menus select Debug - Exceptions

2) Open up the Managed Debug Assistants and uncheck the thrown tickbbox for the items called "ContextSwitchDeadlock" and "DisconnectedContext" MDAs

 

This should in no way affect your compiled program, and unfortunately, without writing our own UPnP Implementation from scratch - which I have started to work on - (ie. not using the Microsoft UPnP COM objects) there isnt a lot we can do about it.

More information on these MDAs can be found on the microsoft site:

http://msdn.microsoft.com/en-us/library/2c1czate.aspx

http://msdn.microsoft.com/en-us/library/ms172233.aspx

 

The context switch deadlock should not cause any memory leaks in this instance as it isnt happening when the UPnP objects are being freed.

 

There are ways around it however, they are very messy, for example do not use any Device / Service COM objects returned by an asynchronous process, instead only use synchronous discovery, but like I said its messy! As you can see they have done it here in the sonority open source code:

http://www.java2s.com/Open-Source/CSharp/Database/sonority/Sonority/UPnP/ZonePlayer.cs.htm

In the second constructor they to see if the current thread is STA and if it is it recreates the device using synchronous methods instead of using the asynchronous device, but personally I dont see the point, as it seems to work fine without doing that anyway.

 

 

Regards,

TheToid

Oct 19, 2011 at 2:12 AM

Thank you, I am relieved now.

Coordinator
Oct 20, 2011 at 11:00 AM

Chloh,

 

When you have some time would you mind doing a review of the ManagedUPnP project for me? Id really like to get some feedback!

 

Thanks,

TheToid

Oct 31, 2011 at 2:28 AM

The CHM is great, keep up the good work!

Coordinator
Nov 1, 2011 at 11:30 AM

Thanks Chloh, what else specifically would you like to see in the chm file?

Nov 4, 2011 at 2:38 AM

None that I can think of yet, will tell you when something comes up :)