Debugging Managed .NET Code Called From Unmanaged

2019-07-06 14:00发布

I've read through the solutions available on SO, but nothing so far has corrected my issue. My start-up project is an unmanaged C++ project (We'll call it TestWrapper). The goal is to have the TestWrapper call a managed C++ project that then calls my C# project. This is working fine and I have no issues running it.

However, I have an exception that has been occuring in my C# code. For some reason, the breakpoints do not get hit and the actual debug break occurs inside of ntdll.dll. I have tried right clicking on the C# project and enabling unmanaged debugging but this does not fix the issue. If anyone could point me toward a solution I'd be extremely grateful.

I'm going ahead and include the project layout:

TestWrapper (unmanaged C++) -> ManagedWrapper (managed C++) -> MyCSharpProject (C#)

I have a feeling it lies in the configuration of the debugging, but I'm not knowledgeable enough to even know where to begin to look.

2条回答
\"骚年 ilove
2楼-- · 2019-07-06 14:11

One idea might be to debug the application from the C# environment. If you're using express, you can set the startup application by adding a couple of lines to in your csproj file

<StartAction>Program</StartAction>
<StartProgram>..path to your app..</StartProgram>
查看更多
可以哭但决不认输i
3楼-- · 2019-07-06 14:20

The debugger must decide on startup if it's debugging native, managed or native + managed code. Hence you must change the debugger settings on the start project and not the DLLs where you're having problems. Try the following

  • Right Click on the project and select "Properties"
  • Navigate to Configuration Properties -> Debugging
  • Switch Debugger Type to Mixed

It's a bit misleading that the debugger settings are even included in DLL projects in Visual Studio. It doesn't have any effect on the system.

查看更多
登录 后发表回答