4

Normally when you reference a COM DLL in a C# project Visual Studio automatically generates the runtime-callable wrapper (RCW) and compiles it to an Interop. assembly.

Is there any way to debug into the source code of the RCW?

Approaches I am thinking of would be to capture PDB files, or to actually include the source of the interop library in the solution.

But from what I can see Visual Studio's behavior when generating the assembly is opaque and not configurable (at least not in any obvious way).

Thanks!

0xced
  • 25,219
  • 10
  • 103
  • 255
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • 1
    The interop library is not the CCW and has no code to debug. It is simply a .NET version of the type library content, just declarations. Not having to equip every .NET language compiler with a type library reader was practical. And it doesn't always end well, sometimes you have to run Tlbimp.exe by hand or manually edit the interop library. So no, nothing to debug, you have to use the debugger of the language it was written in. – Hans Passant Nov 25 '18 at 14:05
  • @HansPassant thanks I see what you mean using a decompiler. The COM functions are just defined extern in C#. What is it that actually performs the marshaling of data etc. which seems to happen automatically when one of those extern functions is called? – StayOnTarget Nov 26 '18 at 16:05
  • 3
    It is automatic, the pinvoke marshaler gets it done in a way that is not different from [DllImport]. The RCW takes care of object creation, lifetime, threading and interface discovery. This is all buried inside the CLR and largely out of reach from eyes and debuggers. – Hans Passant Nov 26 '18 at 16:16
  • @HansPassant got it, thanks again. – StayOnTarget Nov 26 '18 at 16:37

0 Answers0