Debugging a COM object (Runtime Callable Wrapper) with Visual Studio 2010

If you have written managed code that uses a COM object, then you are probably familiar with System.__ComObject. When a COM object lacks a Runtime Callable Wrapper (RCW), the CLR provides a generic RCW which is an instance of the type "System.__ComObject". Unfortunately, one of the downsides to System.__ComObject is that the Visual Studio 2008 debugger cannot display its members.

Let's look at an example. When I was writing this blog post, I wrote a tiny console application that would speak the word "Hello" using the Microsoft Speech Object Library (SpeechLib) which is a COM API.

   1: using SpeechLib;
   3: class Sample
   4: {
   5:     static void Main()
   6:     {
   7:         SpVoice spVoice = new SpVoice();
   8:         spVoice.Speak("Hello", SpeechVoiceSpeakFlags.SVSFDefault);
   9:     }
  10: }

Unfortunately, as soon as I ran the application, the application threw a COMException with the HRESULT 0x8004503A, as shown below.

Application exception

Since I didn't know what the problem was, I added the variable "spVoice" to the Watch window to have a closer look. However, the debugger couldn't show me anything since I didn't have a RCW for SpeechLib and hence the CLR had generated a generic one at runtime. So, I'm somewhat stuck at this point.

Luckily, in Visual Studio 2010, there is now a "Dynamic View" that displays all the members of a COM object of type System.__ComObject, as shown below.


Expanding the "Dynamic View" node displays the members of spVoice. As can be seen from the screenshot below, the reason for the exception was because the audio service on my computer wasn't running. This makes sense since I was running this demo on the Hyper-V virtual machine.


Habib Heydarian.

Comments (0)

Skip to main content