Question

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(..).

Était-ce utile?

La solution

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.

Autres conseils

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).

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

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top