Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug an unhandled exception in managed code when called from COM?

I have a C# .NET component that is being called from a COM out-of-process ActiveX exe.

I can start the debugger in Visual Studio 2005 running on my COM exe which calls my .NET component. Breakpoints work but breaking on an unhandled "Object reference set" exception does not. I have tried the following to no avail:

  • have checked all the CLR exceptions in the VS Exceptions dialog
  • enabled "Break when exceptions cross AppDomain or managed/native boundaries"
  • enabled unmanaged code debugging on my projecy
  • disabled "Just My Code" debugging
like image 218
tekumara Avatar asked May 23 '11 00:05

tekumara


1 Answers

What I typically do is add a call to System.Diagnostics.Debugger.Launch; at the entry point of my managed code. This will launch the debugger if the program is not already actively in debug mode. Keep in mind that you will need to remove this line after you finish debugging, as you would not want to keep a call to launch the debugger in the release version.

like image 195
Drew Avatar answered Oct 15 '22 13:10

Drew