Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Managed .NET Code Called From Unmanaged C++

I've read through the solutions available on SO, but nothing so far has corrected my issue. My start-up project is an unmanaged C++ project (We'll call it TestWrapper). The goal is to have the TestWrapper call a managed C++ project that then calls my C# project. This is working fine and I have no issues running it.

However, I have an exception that has been occuring in my C# code. For some reason, the breakpoints do not get hit and the actual debug break occurs inside of ntdll.dll. I have tried right clicking on the C# project and enabling unmanaged debugging but this does not fix the issue. If anyone could point me toward a solution I'd be extremely grateful.

I'm going ahead and include the project layout:

TestWrapper (unmanaged C++) -> ManagedWrapper (managed C++) -> MyCSharpProject (C#)

I have a feeling it lies in the configuration of the debugging, but I'm not knowledgeable enough to even know where to begin to look.

like image 564
Chuck Callebs Avatar asked Jun 23 '26 00:06

Chuck Callebs


2 Answers

The debugger must decide on startup if it's debugging native, managed or native + managed code. Hence you must change the debugger settings on the start project and not the DLLs where you're having problems. Try the following

  • Right Click on the project and select "Properties"
  • Navigate to Configuration Properties -> Debugging
  • Switch Debugger Type to Mixed

It's a bit misleading that the debugger settings are even included in DLL projects in Visual Studio. It doesn't have any effect on the system.

like image 96
JaredPar Avatar answered Jun 25 '26 15:06

JaredPar


One idea might be to debug the application from the C# environment. If you're using express, you can set the startup application by adding a couple of lines to in your csproj file

<StartAction>Program</StartAction>
<StartProgram>..path to your app..</StartProgram>
like image 31
PeskyGnat Avatar answered Jun 25 '26 15:06

PeskyGnat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!