Version 1.1 of the .NET Framework introduces a handy feature called Customer Debug Probes (CDP). These probes enable you to find and diagnose difficult bugs lurking in managed code, even in a production environment.
I'll share the details of each probe in future blog entries, so stay tuned. In the meantime, I've uploaded a tool (with source code) to gotdotnet.com called CLR SPY that makes it easy to use the probes. Here's a screenshot:
CLR SPY runs in the taskbar notification area. It can display balloon tooltips and/or log messages to a file. Here's an example of it in action:
To get a feel for the tool, add any managed application to the "Monitored Applications" list and run it with the Marshaling probe enabled. You should see a flurry of messages appear as parameters get marshaled to unmanaged code.
This dynamic analysis tool is a great complement to FxCop's static analysis for writing high-quality managed code. Use it to find your bugs before your customers do! Let me know what you think of the tool!
Note: When using debug probes, you could run into bugs (or unwanted noise) in components you depend on - even in the .NET Framework! For example:
- Windows Forms applications that take advantage of the new v1.1 Application.EnableVisualStyles feature (which gives you Windows XP themes without the use of a manifest) trigger the PInvoke Calling Convention Mismatch probe when shutting down (or potentially other times, like if the application calls Application.DoEvents). That's due to a bug in a PInvoke signature inside System.Windows.Forms for the Win32 DeactivateActCtx API.
- Unmanaged applications that load the CLR by cocreating a managed object on an STA thread provoke the Thread Changing Apartment State probe. That's because when the CLR is loaded, it tries to initialize the thread's apartment state to MTA even though it has already been set. For example, this harmless message appears when VS.NET loads the CLR (typically when you open a new managed project).
If you run into other violations reported by the probes that you don't think are your fault, let me know.