4

I have inherited an application consisting of a number of C#, C++/CLI and native C++ projects.

The app starts as an MFC application but loads the CLR during startup (via a process I'm not sure I fully understand yet).

I've found that I can place breakpoints in native C++ code and that these work as expected. However, breakpoints in managed code do not work.

In C# I get:

"The breakpoint will not currently be hit. No symbols have been loaded for this document".

In C++/CLI I Get:

"The breakpoint will not currently be hit. No executable code is associated with this line. Possible causes include: preprocessor directives or compiler/linker optimizations".

I can even set two breakpoints in the same C++ file and have only one work, e.g.

#pragma unmanaged

int CMyClass::UnmanagedFunc()
{
    // Breakpoint here works
    return 1
}

#pragma managed

int CMyClass::ManagedFunc()
{
    // Breakpoint here DOES NOT WORK!!
    return 2
}

The project settings for "Enable unmanaged code debugging" (within the managed library projects) has no effect on these breakpoints. Is there some setting or config or something that I do do to allow me to interrupt and step through the managed parts of the code base?



: The process loads mscoree.dll, and involves a complicated routine including CLRCreateInstance, ICLRMetaHost, ICLRRuntimeHost, GetRuntime(..), Start() and ExecuteInDefaultAppDomain(..).

Grhm
  • 6,726
  • 4
  • 40
  • 64

4 Answers4

12

Since your main EXE is a native program, it is likely that the debugger starts up in unmanaged mode and will therefore not support setting breakpoints on managed code. Project + Properties, Debugging, Debugger Type setting. Change it from the default of Auto to Mixed or Managed Only. Mixed debugging only works in 32-bit mode.

UPDATE: starting with VS2012 you also have to force the debugger to use the legacy managed code debugging engine, the one that still supports C++/CLI. Tools > Options > Debugging > General > "Use managed compatibility mode" setting.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • D'oh. I knew it'd be something simple I was overlooking. Changing this from "Auto" to "Mixed" has done the trick..... – Grhm Nov 13 '12 at 08:52
  • 3
    Combining this answer with tools->Options->Debugging->General turn 'Use managed compatibility mode' solved the issue for me. Tnx! – NP83 Mar 18 '14 at 11:21
2

For me, the key was to change debugger type from Auto to Mixed, but for the startup application, not the library which contained the C++/CLI code (which is what I was trying to do).

Dženan
  • 3,329
  • 3
  • 31
  • 44
0

For the same error it works with me when I specified debugger type to:

"Native Only" or "Managed Only" not to Mixed or Auto!!!

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
H. Ali
  • 1
0

For me it was in project properties -> Linker -> Debugging -> Debuggable Assembly set to YES (/ASSEMBLYDEBUG)

Myfero
  • 204
  • 3
  • 7