Search code examples
c#visual-studiovisual-studio-debuggingunmanagedcode-inspection

Inspect unmanaged C++ objects/variables on Visual studio 2017


So i have one C# desktop application that references a C++ dll. This dll project was developped by other persons, it can't be compiled on visual studio, I use NMake with the parameter -DCMAKE_BUILB=Debug to generate the .dll & .PDB files. I copied the files on the C# project reference folder and enabled Debugging of Unmanaged Code in the project properties. So im actualy able to debug unmanaged code from the dll. My issue is that i can't inspect any of the object nor the variables im lokking in the unmanaged code side. The visual studio contextual inspector doen't show when I passe my mouse on the objects/variables & when trying to add a spy it's not better. I need to see the values of the objects/variables from the unmanaged code to make sure it doen't do anything wrong.

Note : a coworker of mine had already opened a thread here How add spy on Visual studio using unmanaged code But sadly the thread was closed for lack of details, so I tried to add more details to describe the issue. Pls don't close this one


Solution

  • Inspect unmanaged C++ objects/variables on Visual studio 2017

    Suggestion

    Update 1

    Please make sure that you have installed the C++ development and C# development workload in VS Installer. That's all the premises.

    1) when you reference the path of the dll, make sure that the pdb file already exists under the reference folder(the folder where you referenced the dll) and then use DLLImport node to import the c++ functions.

    2) Tools-->Options-->Debugging-->General-->check the option Used Managed Compatibility Mode

    3) Right-click on your C# project-->Properties---> Debugging-->check the option Enable native code debugging

    Also, check Allow unsafe code option under Build.

    4) also, if your c++ dll is built with x64 platform, you should also use x64 platform to debug your c# main project.

    In addition, you can refer to this similar issue for more detailed info.