CLR has been unable to transition from COM context for 60 seconds

I was debugging an inherited multi-project WinForms application (from my co-worker and friend, Genaro Quismorio) today and came across this error twice (below), which was frustrating, annoying and very unproductive. This error occurred while stepping through a breakpoint [Debug.Break] in my WinForms code while looking for a bug.

One fix I found on Google was to go to Debug > Exceptions > Managed Debug Assistants (MDA), and then unchecking the ContextSwitchDeadlock option; I didn’t have this option under VS.NET 2005 Team Edition for Software Testers. Unfortunately, this setting is not global across projects, which means that I have to set it every time for each project.

Managed debugging assistants (MDAs) are debugging aids that work in conjunction with the common language runtime (CLR) to provide information on runtime state. The assistants generate informational messages about runtime events that you cannot otherwise trap.

A little more research around the Internet spectrum landed me on this article (on the MSDN website), which basically shows you how to globally turn off MDA. There are apparently two-and-a-half ways to do it: registry key, an environment variable, or application configuration settings.

Registry Key

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFramework]
"MDA"="0"

Environment Variable

1. Add COMPLUS_MDA (this overrides the registry key).

  • 0 – Deactivates all MDAs.
  • 1 – Reads MDA settings from ApplicationName.mda.config.
  • managedDebugger – Explicitly activates all MDAs that are implicitly activated when a managed executable is started under a debugger.
  • unmanagedDebugger – Explicitly activates all MDAs that are implicitly activated when an unmanaged executable is started under a debugger.

If there are conflicting settings, the most recent settings override previous settings:

  • COMPLUS_MDA=0 disables all MDAs including those implicitly enabled under a debugger.
  • COMPLUS_MDA=gcUnmanagedToManaged enables gcUnmanagedToManaged in addition to any implicitly enabled under a debugger.
  • COMPLUS_MDA=0;gcUnmanagedToManaged enables gcUnmanagedToManaged but disables those MDAs that would otherwise be implicitly enabled under a debugger.

Application Configuration Setting

To enable the use of an application configuration file for configuring MDAs, either the MDA registry key or the COMPLUS_MDA environment variable must be set (this is why I said two-and-a-half ways). Simply create a .config file of format ApplicationName.mda.config; for example, notepad.exe.mda.config.

<mdaConfig>
  <assistants>
    <marshaling>
      <methodFilter>
        <match name="*"/>
      </methodFilter>
      <fieldFilter>
        <match name="*"/>
      </fieldFilter>
    </marshaling>
  </assistants>
</mdaConfig>

That’s it. You can read more about it here. Hope this helps you somewhat.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.