简体   繁体   中英

Debugging c++ cli from c# - c++ breakpoints not hit

I have a solution with ac# win-exe-64 project referencing a c++ (managed,cli,64) library vcxproj. Using Visual Studio 16.10.3.

All works fine and I can use the classes from c++ in c#.

Problem is the debugging, stepping in the c++ code is not working and also breakpoints in the c++ code are not hit. The breakpoints in c++ are showing "Breakpoint will not currently be hit. No symbols have been loaded for this document."

In the ide when I check Modules window, it says: "Symbols loaded" for this specific dll. In the Process window it indicates "Debugging: Managed (.NET 4.x), Native"

I tried so many settings already:

  • Ide: Tools-Options-Debugging-Use managed compatibility mode: on/off
  • win-exe: properties: Enable native code debugging: on/off
  • c++ lib: Properties.Debugging-Debugger Type: Mixed(.net framework), Native

But nothing helps, breakpoints are just not hit.

What also wonders me, "Goto definition" on a c++class member in c#-code just brings the class definitions generated from metadata, it doesn't go to the source.

Any ideas?

Update: the screenshot showing modules-window, dll and pdbs loaded from exe-folder. Right windows main process c# exe calling c++ dll in left window. 模块窗口

There're several possible solutions. Here I'm mentioning some of them which I've come across.

  1. Make sure your VS Solution Configurations is in Debug mode.

  2. Remove all previous debug points. (Debug -> Delete all breakpoints)

    Unload the project from VS. (or close VS)

    Delete all previous bin, obj, x64/x84 folders from File Explorer.

    Open VS and load the project in VS.

    Clean project -> Set your debug pointer -> build -> run

  3. Debug -> Options -> General -> Remove the check mark from option " Enable Just My Code "

    (It also works in some cases if point 1 & 2 is note enough)

When I faced similar problem, I solved it following point 1 & 2.

For your convenience I'm giving screenshot of my workable VS.

VS Debug -> Options -> General ->

VS 调试 -> 选项 -> 常规 ->

Project Properties -> Build ->

项目属性 -> 构建 ->

Tutorial: Debug C# and C++ in the same debugging session

Visual Studio lets you enable more than one debugger type in a debugging session, which is called mixed-mode debugging. In this tutorial, you learn to debug both managed and native code in a single debugging session.

May be you are missing something in the step. As per your question please follow the following link.

Debug configuration and x86 or x64 platform

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM