Cannot Debug Unmanaged Dll from C#
Solution 1
To debug into your C++ DLL you need to enable mixed mode debugging on the startup application in your solution.
- Right click on project -> Properties
- Go to Debug Tab
- Check "Enable unmanaged code debugging"
This will allow you to debug into native code for an F5 style scenario. If you want to enable it for attaching to the process then do the following in the "Attach to Process" Dialog
- Select the process to debug
- Click on the "Select ..." button above the process list
- Click "Debug these code types"
- Check both Managed and Native
Solution 2
You need to enable unmanaged (Native) debugging.
If you are attaching to the process after it is started:
Go to the Tools menu, and then attach to process, make sure you have native debugging enabled.
You will see a read only edit box:
Attach to: Managed code, Native code [Select]
Make sure Native code is listed there. If not add it.
If you are starting your project from within visual studio:
On your project properties that you are starting in debug mode. Go to the project Properties, and then select the debug tab.
Make sure this checkbox is checked on:
Enable unmanaged code debugging
Solution 3
When you attach to a process to debug, you have to specify how you want to attach. You have a few options, namely Managed, and Native. In order to debug C# code with unmanaged C++, you have to attach to a process as Managed and as Native (both can be selected at the same time).
QueueHammer
Software Developer, Runner, Pragmatist. Web Page: http://cmsmith.co Twitter: https://twitter.com/cmsmithco
Updated on October 14, 2020Comments
-
QueueHammer over 3 years
I have a DLL that was written in
C++
and called from aC#
application. TheDLL
is unmanaged code.If I copy the
DLL
and its.pdb
files with a post build event to theC#
app's debug executiondir
I still can't hit any break points I put into theDLL
code. The break point has a message attached to it saying that "no symbols have been loaded for this document".What else do I have to do to get the debugging in the
dll
source?I have "
Tools
->Options
->Debugging
->General
->Enable
only my code" Disabled. TheDLL
is being compiled with "Runtime tracking and disable optimizations (/ASSEMBLYDEBUG)" and Generate Debug Info to "Yes (/DEBUG)"