12

I have the following three projects in my solution: 1. C# library 2. C++/CLI managed code 3. C++ unmanaged code

I did check "Enable Unmanaged Code Debugging" in my C# project, and built both C++ projects in Debug/Win32. However, I cannot step into unmanaged code - when I F11 on the call of any unmanaged method, it shows me some random/wrong code then exits.

Because my unit tests pass, I know that my unmanaged code does execute.

What am I missing?

Arne Lund
  • 2,366
  • 3
  • 26
  • 39
  • 1
    Do you have the .pdb files for the unmanaged code you're trying to step into? – Steven Behnke Aug 02 '11 at 19:50
  • you could try to start the managed process and pause it (by whatever means), place a breakpoint in your unmanaged project and select "Debug -> Attach process", select the managed process and continue the managed process. – Philipp Aug 02 '11 at 19:52
  • @Steven: yes I do see vc90.pdb – Arne Lund Aug 02 '11 at 20:37
  • @Arne: Which functions are you trying to step into? vc90 is the Visual C Runtime for Visual Studio 2008. This includes the standard C library and not much else. – Steven Behnke Aug 02 '11 at 21:26

2 Answers2

10

When I've had this problem it has come from one of these things:

1) Enable unmanaged code debugging not checked. You already fixed this.

2) Built the EXE as x64 or Any CPU (they say x64 works, but it doesn't). I think you already fixed this.

3) "Just my code" being turned on sometimes causes trouble with unmanaged code debugging (Tools, Options, Debugger, Just My Code)

4) Incorrect debug options in the C++ project settings

5) Missing, corrupted or mismatched PDB files. You can check for this by trying to set a breakpoint in your C++ code while running in the debugger. If the breakpoint turns into a hollow circle, something is wrong with your debug info. Also check your output window as you run in debug mode -- it should tell you whose symbols got loaded.

Ed Bayiates
  • 11,060
  • 4
  • 43
  • 62
4

I've seen this issue going the "other" way from time to time (ie, from native C++ to C++/CLI) and it's usually caused by the debugger not really picking up that it's supposed to debug both native and managed code.

Usually for me, setting the Debugger Type in Configuration Properties -> Debugging in your startup project from 'Auto' to 'Mixed' solves the problem.

Timo Geusch
  • 24,095
  • 5
  • 52
  • 70
  • I switched from 'Auto' to 'Mixed', that did not help me. – Arne Lund Aug 02 '11 at 20:39
  • Me neither. My breakpoint gets hit, but I get no information about any variables in Locals or Watch window, etc. – Scott Hutchinson Apr 21 '17 at 22:32
  • I saw this too. If I just F5 debug or attach to a C# EXE, VS didn't want to load the mixed debugger. Every time I debugged I needed to specify I wanted both native and .NET debuggers. – Carl Walsh Sep 09 '17 at 17:53