CLR SPY and Customer Debug Probes: The Disconnected Context and Unmarshalable Interface Probes

When managed code interacts with COM objects via RCWs, the CLR handles the COM plumbing for you.  An important part of this plumbing involves marshaling wrapped interface pointers across contexts.  When a COM interface pointer needs to be marshaled from one context to another, the CLR calls CoMarshalInterface in the original context to marshal the…


Quiz: Gotcha with Exceptions and HRESULTs

The C# code below, when executed, prints the following:   0x80004002   0x80004002 Who can figure out why the second line printed isn’t 0x80004003? using System; using System.Runtime.InteropServices;   public class Quiz {   const int E_NOINTERFACE = unchecked((int)0x80004002);   const int E_POINTER = unchecked((int)0x80004003);     public static void Main ()   {    …


CLR SPY and Customer Debug Probes: The Invalid IUnknown and Invalid VARIANT Probes

Whereas probes like Collected Delegate or Object Not Kept Alive catch coding mistakes in managed code, the Invalid IUnknown and Invalid VARIANT probes typically inform you when you’re attempting to interoperate with a broken COM component.  Either that, or the metadata you’ve got for the unmanaged API doesn’t match reality. Whenever wrapping a COM interface…


CLR SPY and Customer Debug Probes: The Object Not Kept Alive and Buffer Overrun Probes (A Quiz)

The Object Not Kept Alive and Buffer Overrun probes are unlike any other CDPs, because they do not output any messages to report bugs in your code.  Instead, they change general CLR behavior with the goal of forcing non-deterministic bugs that can be almost impossible to reproduce into bugs that will happen every time you…


TechEd Book Signing

I’ll be doing a book signing (for .NET and COM: The Complete Interoperability Guide) at the TechEd Mall tomorrow (Wed. 6/4) from 11:30-12:30 – immediately after the Interop presentation.  If you’re at TechEd, please stop by!


CLR SPY and Customer Debug Probes: The Collected Delegate Probe

The most common mistake made when passing a delegate to unmanaged code (marshaled as a function pointer) is to allow the delegate to be garbage collected before unmanaged code is finished using it.  This can happen because unmanaged code is invisible to the CLR garbage collector; it has no way to know when a delegate…


TechEd Bloggers

Tomorrow morning I’m headed for Dallas, Texas to speak at TechEd 2003.  Sonja Keserovic and I are giving the following talk: Interoperating with Unmanaged Code (DEV341)Room: D166   Time Slot: Wed, June 4 10:15 AM-11:30 AMMoving to the .NET Framework does not mean rewriting all of your existing code. Learn how to use platform invoke and…


CLR SPY and Customer Debug Probes: The PInvoke Calling Convention Mismatch Probe

Defining a PInvoke signature and using DllImportAttribute correctly can be difficult to do, and you normally get little-to-no diagnostic information if you make a mistake.  Some mistakes that can be made with PInvoke would be impossible for the CLR to detect, but many mistakes pass through without validation because PInvoke is designed for high-performance access…


CLR SPY and Customer Debug Probes: The Marshaling Probe

As promised, here’s my first entry with more details about Customer Debug Probes and CLR SPY. The Marshaling probe is the easiest one to understand and great for experimentation since it’s the only one that doesn’t report on error/warning conditions.  It also fits best into the spy theme since it non-intrusively reports on work that…