32

I have a DLL that was written in C++ and called from a C# application. The DLL is unmanaged code.

If I copy the DLL and its .pdb files with a post build event to the C# app's debug execution dir I still can't hit any break points I put into the DLL 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. The DLL is being compiled with "Runtime tracking and disable optimizations (/ASSEMBLYDEBUG)" and Generate Debug Info to "Yes (/DEBUG)"

4 Answers 4

62

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
7
  • While I was going to answer this, I wasn't sure if it was so simple or not. If it is this simple, I've likely always misused it while attempting to debug managed C++ code that interfaces with native code. Nov 16, 2009 at 21:19
  • 3
    Note that if your startup project uses another C# DLL project that actually calls the C++ DLL, the startup project must also have "Enable unmanaged code debugging" turned on. Feb 17, 2012 at 23:54
  • 2
    Select solution in Solution Explorer. Select from >Menu|Tools|options|Debugging|General and Uncheck "Require source files to exactly match the original version"
    – Martin
    Jan 12, 2013 at 6:38
  • 3
    For VS 2013, the setting is now called "Enable native code debugging", still in the Debug tab of the project properties.
    – chappjc
    Sep 25, 2014 at 21:09
  • 1
    Also don't forget: Tool | Options | Debugging | General at the bottom ensure that "Use Managed Compatibility Mode" is checked.
    – Chris O
    Nov 10, 2014 at 1:09
4

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

1

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).

1

Had faced the same issue and did all that was suggested in the accepted answer but the breakpoints in the unmanaged DLL was not getting hit!

However, when i did the following i could finally debug the DLL!

Select solution in Solution Explorer
Select from Menu>>Tools>>options>>Debugging>>General
Uncheck "Require source files to exactly match the original version"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.