views:

299

answers:

0

I have an application that consists of managed and unmanaged DLLs. My managed DLL is a C++/CLR DLL that is used to access a native C++ DLL. When code crosses from managed to native the logic is wrapped in a try/catch statement. The purpose is to log any exceptions before we rethrow them.

C++/CLR code calling into native code.

   try
   {
      // Calling native code here.
      UnmanagedFoobar::crash();
   }
   catch ( System::Exception^ e )
   {
       // log exception info here and then rethrow
   }

Assume the following program flow.

C++ (CLR) function calls -----> C++ ( native )

Here is the call stack just before the access violation will occur. Notice that we are in the native DLL in the 'UnmanagedFoobar::crash()' method.

The real call stack:

 *>    UnManagedLibrary.dll!UnmanagedFoobar::crash()   C++
      [External Code]
      ManagedLibrary.dll!ManagedFoobar::CallUnmanagedCrash()      C++
      ClientConsole.exe!ClientConsole.Program.Main({string[0]})   C#*

Call Stack Missing Data

When the exception is thrown here is the call stack property of the exception when it comes back to the C++/CLR DLL.

   at UnmanagedFoobar.crash()
   at ManagedFoobar.CallUnmanagedCrash() in c:\projects\managedandunmanaged\managedlibrary\managedfoobar.cpp:line 17

My problem is that the call stack member of the exception is missing the native's call stack which is part of what I want to log.