Unable to debug native code from managed despite enabling native code debugging
Asked Answered
E

1

7

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://learn.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

Exhibit answered 9/3, 2020 at 15:8 Comment(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.Ctesiphon
S
3

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.

Sanitize answered 10/3, 2020 at 11:32 Comment(1)
the solution I'm working on is pretty big, but I did steps 1-4 and i still cannot inspect native variables. i'll try to try 5 tomorrow... if it does or doesn't work, what does that mean? note breakpoints are hit in both managed and native code (that was never the problem). I really don't want to do a repair.Exhibit

© 2022 - 2024 — McMap. All rights reserved.