8
votes

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
2
When you checked all the CLR exceptions in the VS Exceptions dialog did you use the user-unhandled column or the thrown column? It's only a guess but I suspect COM/Managed interop code would be handling exceptions so it could turn them into suitable HRESULT values.Frank Boyne
I checked both user-unhandled and thrown. I think you are right Frank - COM is handling the exceptions. I've found this blogs.msdn.com/b/oldnewthing/archive/2011/01/20/10117963.aspx but not sure how to set IGlobalOptionstekumara

2 Answers

3
votes

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.

1
votes

Instead of running your programming with F5, you can run the unmanaged program and then attach to it:

For Visual Studio 2005:

  • Run (not debug) the unmanaged project from Visual Studio with Ctrl+F5
  • Open the "Attach to Process" dialog: Debug -> Attach to Process...
  • Click the Attach to: selection button: Select...
  • Choose: Debug these code types:
  • Check these items: Managed, Native
  • Click OK
  • Choose your process from Available Processes
  • Click Attach

This should enable both managed and unmanaged debugging in an unmanaged process. You can now set breakpoints or catch first-chance exceptions in managed code, assuming you have symbols.