简体   繁体   中英

Enabling “Native Code Debugging” in C++/CLI/C# project crashes application

I have a project in Visual Studio 2019 where I am creating a C# interface to a C Library. Everything works fine when I run with the default debug settings, but when I come to add to watch list an STL variable (std::vector, std::string, etc) I get an error message in the watch list saying that I need to enable Mixed mode. After a google search I find the procedure to do this, but this time it crashes the program with "WNTDLL.pdb is no loaded". Leaving the mixed mode active but disabling "Enable native code debugging" fixes the issue, but I still cannot see STL containers.

Are there any other things I need to change in my settings to avoid this crash? What am I doing wrong?

I've tried a few other settings like "Just my code" but that didnt make a difference. There was one issue that arose when installing Visual Studio 2019 where I could not run the "Hello World" default project in C++. I fixed this by first creating the same hello world in Python which somehow fixed the C++ debugger. Could this be a corrupt debugger?

Obviously I expect the program not to crash and instead to allow me to peak inside vaiables and stl containers just like when in a normal C++ application.

You should first revert your settings to the state you get the error:

WNTDLL.pdb not loaded

Now, what does this mean? It means you either do not have the debugging info - specifically the program database file (.pdb) for the dll you want to debug, or it is corrupted.

Thus, you need to make sure that the symbols are correctly loaded. In the case of WNTDLL you need to make sure the Microsoft Symbols Server is available to you and you have it enabled in your symbol path settings ( Debug > Options > Symbols ). For more info you can also look at this question .

EDIT: To elaborate a bit on the rest in your question:

The setting Enable native code debugging does exactly as it says. In your case you want to have it enabled otherwise you won't be able to debug your native library (See here ). Mixed mode with the option disabled is basically just managed code.

The setting Just my code again does as it says. It automatically steps over calls to non-user code . In your case you want to have it disabled as WNTDLL is not your code. You can see the recognition of different modules in the modules window while debugging.

I can't say anything about the issue you had with "Hello World", but I can say that the .pdb problem is for sure the one I explained above.

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