I have a multithreaded project im working on and the startup project is set to a c# project that runs my UI. Then there is a whole series of underlying c++ native projects which are connected to the C# by managed C++/CLI projects. I've enabled in the c# start up project 'Enable Unmanaged debug' and when I attempt to debug the native code, I am able to hit break points I set. However, it hangs after I try to run it again and try to hit a break point again. For example, if I have a loop I try to hit inside it in each iteration, after the second iteration the program hangs and I have to force quit. Im working in Visual Studio 2010. Debugging beginning to prove not too useful at this rate, is there any way to preclude this problem?
问题:
回答1:
When I want to debug native code as well as C++/CLI, I do following:
- In C# application, check
Allow unsafe code
in Build tab andEnable unmanaged code debugging
in Debug tab of project properties. - For C++/CLI dll project, In Debugging tab of properties, set Debugger Type to
Mixed
回答2:
We also had problems debugging complex mixed code applications and found out that the Visual Studio is not that reliable in these situations. My suggestions would be to:
If you're trying to debug a piece of native code try to use a native project as the debugger start-up application. Under the project settings, "Debugging" tab set the "Debugger Type" to "Mixed", for us this helped sometimes (the native project can be a DLL for example, simply set your main Exe as debugging target in the project settings);
Use WinDbg, with it you can debug both managed/unmanaged mixed code applications much more reliably;
回答3:
I had the same problem when I tried to step into un-managed code from managed, so instead, I got rid of all the breakpoints on the managed side and did the following:
1) open your un-managed source file via File->Open->File (i.e my source.cpp)
2) set a breakpoint there
3) start your managed code debugging (Play button)
It should break directly into your un-managed code... at least it works for me...