15.5 Digging into Your Program’s CLR Interactions with PInvoke and COM Using CLR SPY

Most people agree that writing managed code is more pleasant than writing unmanaged code. With the support of the Common Language Runtime and rich class libraries in the .NET Framework, managed code takes rapid application development to a whole new level. But the downside of this built-in infrastructure is that the CLR can be a bit of a “black box.” Debugging problems can be difficult, especially when using the CLR’s interoperability features to integrate managed and unmanaged code.

Fortunately, the CLR team recognized these difficulties and introduced Managed Debugging Assistants (MDAs) that enable you to find and diagnose difficult bugs lurking in your managed code. They can even force nondeterministic bugs, which are almost impossible to reproduce, into appearing every time you run your application.

In essence, MDAs open up the black box of the CLR. In version 1.1 of the .NET Framework, all of the MDAs focused on interoperability. In version 2.0 of the .NET Framework, however, the set of MDAs has been greatly expanded to cover diverse aspects of managed programming.

Previously—especially in .NET 1.1—MDAs were not easy to use. They required obscure syntax inside XML configuration files, and their output was visible only in a debugger or a tool like dbmon. CLR SPY solves this problem with a simple mechanism to enable MDAs and capture their output. It even lets you do this in a production environment, ...

Get Windows Developer Power Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.