Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug and step into a native code project from inside a .NET core C# project?

I am developing a .NET core (.NET Standard 1.6) application in VS2015. The application calls C++ code via P/Invoke. Now I need to step into the C/C++ code of my native dll project.

In regular .NET application, by enabling unmanaged code debugging in the property window of the application, we can step into the C/C++ code directly:

step into the C/C++ code

But I can't find such option on a .NET core project. And I know that I can attach the debugger to the application to debug native code only, but that's not suitable for my case.

Again, I want to debug from managed C# code into native C/C++ code.

Any ideas?

Maybe I should switch back to .NET Framework so I can debug the native code. It's really hard to debug by printf. :(

like image 576
zwcloud Avatar asked Nov 01 '16 07:11

zwcloud


1 Answers

UPDATE
The mixed mode debugging, i.e. debugging from managed C# code into native C/C++ code, has been implemented. See Tutorial: Debug managed and native code in Visual Studio.

UPDATE
The feature may have already been implemented, see this.


Just as @cynic said, this is not yet supported now (2016-11-1).

That can be verified by following steps provided by cynic.

  1. Put a pause in your program (e.g. a Console.ReadKey call).
  2. Attaching to the dotnet.exe process selecting "Managed (CoreCLR)" and "Native" code types
  3. You'll get a message box stating explicitly that "Interop debugging is not supported".

Not supported.

Here is a proper way to debug the native dll.

  1. Right click on the solution, Add Existing Project
  2. Open 'dotnet.exe'. This is normally installed to 'C:\Program Files\dotnet\dotnet.exe'.
  3. You should now see another node in solution explorer for dotnet.exe. Right click it to bring up project properties:
  4. Change the working directory to be what you want
  5. Change the arguments to be the path to your built dll
  6. Change the exe project to your startup project

RECOMENDED: Go to Tools->Options->Projects and Solutions->Build and Run, uncheck 'Only build startup projects and dependcies on Run'

like image 176
zwcloud Avatar answered Nov 02 '22 10:11

zwcloud