2
votes

I have a managed project (.net 4.6.2) which calls into a native dll. If I put a breakpoint in the native code, it hits it, but if I try to inspect stack variables I get a rather annoying

Inspection of unmanaged type 'MyTypeInHere*' requires unmanaged debugging to be enabled. Please set the debugger type to 'Mixed' and try again

I followed steps from https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-debug-managed-and-native-code?view=vs-2019, Debugging unmanaged code while debugging managed code but I still cannot inspect types.

In the managed project properties, under debug I've enabled enable native code debugging and under the build page I've checked allow unsafe code. Further in launchSettings.json, I have "nativeDebugging": true

Also note that in the native project property settings I've set the Debugger type to mixed.

Does anybody know what's preventing me debugging native code?

Thanks

1
When the breakpoint works then you can be sure that you configured the debugger correctly. You have to be a bit careful about clicking in the Stack Trace window, it lets you jump to a managed method. That switches the debugger engine, it now doesn't know anything about unmanaged code anymore.Hans Passant

1 Answers

1
votes

Does anybody know what's preventing me debugging native code?

It is quite strange and I followed the sample which your link provided and it works well. In fact, all the steps are just the rule.

So please check these:

1) Please make sure that your c++ project is using Active(Debug) Configuration and x64 platform. When you change Debugger type to mixed and then click Apply, please remember to rebuild the project.

2) when you reference the native code into C# project, please close the VS Instance, delete obj,bin,.vs hidden folder and then reopen your c# project. After that, please make sure that you check Enable Native Code debugging, then rebuild the entire solution.

3) Add breakpoints where you want to break and begin stepping through the code. Make sure your have placed your breakpoints in code which the C# application calls into.

4) change the target gramework to 4.7.2 to test again.

5) Please try to create a new net framework 4.7.2 c# project to test whether the issue is caused by the old project.

In addition, if all the steps does not work, please do a repair in VS Installer.