Debug c++ dll in C#

30,225

Solution 1

If I understand you correctly, you want to debug a C++ coded DLL that you created, in a C# project that calls the DLL, which you also created?

I've done this before by going into your C# project properties, and under the Debug section, checking the "Enable unmanaged code debugging" check box. This should allow you to step into your C++ DLL.

Solution 2

To debug a C++ from C# there a couple of things you have to do.

  1. Add a C# project to you solution for your debug application.
  2. Edit the properties of the C# project to "Allow unmanaged code debugging" on the "Debug" tab of the project properties.
  3. Set the C++ project as a dependency of the C# project.
  4. Write code in your C# project to use the DLL either using P/Invoke or COM.
  5. Set some breakpoints in your C++ code and run the C# project.

Solution 3

I overcame this in Visual Studio 2019 by selecting "Enable native code debugging" as shown under my C# project's properies.

enter image description here

Solution 4

Visual Studio cannot execute a dll on its own.

You need to set the startup .exe that will be using your C++ dll in the properties of your dll project. You can do so from properties --> debugging --> command specifying the path of the executable that's gonna call your dll and any command line argument needed.

Solution 5

For VS 2017 Pro, go to the property page of the main project (your c# project in the solution) by right mouse clicking it. At the Debug menu item, find the option in Debugger engines, choose Enable native code debugging.

Share:
30,225
Admin
Author by

Admin

Updated on August 10, 2021

Comments

  • Admin
    Admin almost 3 years

    I have a .dll from c++ and I want to debug it in C#, but I don't know how to.

    When I compiled the c++ project, Visual studio asked me to execute an ".exe".

    I supposed that I had to create a project to execute the dll.

    But I am lost, how could I debug it?

  • Darius
    Darius over 9 years
    Also, in Visual Studio 2012 I found the option to be called 'Enable native code debugging'
  • Doug Null
    Doug Null almost 6 years
    ...yes, that's what my VS 2017 Pro has -- no "Enable unman code deb."
  • Fil
    Fil about 4 years
    Similarly, if you have a C# DLL to debug in native c++ project, choose 'Debugger type = mixed' in Debugging section of native c++ project. This will allow to step into cli/clr and c# code.
  • Chris
    Chris almost 4 years
    Does anybody know how to configure this for a .NET Core app in VSCode?