Did you know that the VS Debugger can cause exceptions?

Yes, sadly, you read that right. I’ve only found 1 case when testing an application at work in which the application doesn’t run through to the end properly because the error raises the following exception at a specific point in processing.

The CLR has been unable to transition from COM context 0x1afb80 to COM context 0x1afcf0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

This is a ContextSwitchDeadlock was detected Message that the Managed Debugging Assistant (MDA) throws at you.
MDAs are debugging aids that work in conjunction with the common language runtime (CLR) to provide info on the runtime state and generate useful info about runtime events that you can’t otherwise trap

(You can read more about MDAs here: http://msdn.microsoft.com/en-us/library/d21c150d(VS.80).aspx)

I’d go into it, but that’s not the focus of this post, although it is definitely helpful.

You can, however, configure MDAs in VS2005 by going to the Debug >> Exceptions… menu, and opening the Managed Debugging Assistants tree. There you’ll find a list of the MDAs that are thrown. Deselect the ContextSwitchDeadlock item and you can continue to debug the application.

I didn’t know this when I got the error, so I just published my app and ran it fine (after I’d found out that it was the debugger causing the error).

I’ll be posting more about the ContextSwitchDeadlock exception at a later stage, so keep an eye open for that.

Until next time…



Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s