5

My project has several new C# modules and one C module (not C++) compiled using win32 system calls. I'm using the PInvoke interop layer to call the C code from the C#. The C function is getting called.

All modules are writing to a single bin directory and all write pdb files.

On running, and then stopping at a breakpoint right before a call into the C.dll, I see the breakpoints in the C module are disabled. Looking at the Debug|Windows|Modules list I don't see the C.dll module loaded even after the call has been executed.

One more factoid: in Solution|Properties|Configuration Properties|Configuration is shows the C# modules using Platform = "Any CPU" and the C module using "Win32"

Why isn't the module loaded and why aren't its symbols loading?

Thanks, Max

3 Answers 3

13

I've consolidated answers from several sources.

  • Are you running the debug configuration?
    In the Solution check: SolnExplorer|Solution|Properties|ConfigurationProperties| Configuration = Debug
    and: SolnExplorer|Solution|Properties|ConfigurationProperties| Configuration|ProjectConfig[]=Debug -->Note:Although breakpoints will work with release configuration, sometimes the lines may be optimized out or rearranged.

  • Are you generating debug information? In C# projects: SolnExplorer|Project|Properties|ConfigurationProperties|Linker|Debugging|Generate Debug Info=YES
    In C++ projects: SolnExplorer|Project|Properties|ConfigurationProperties|C/C++|Debug Information Format = Program Database(/Zi)
    -->Note: It pays to check the command line arguments.

  • Is everything is being rebuilt? If the PDB is out of sync, the debugger may not be able to load symbols:
    In Solution: SolnExplorer|Solution|Properties|Configuration Properties|Build=TRUE(Checked) for all projects.

  • Can you debug unmanaged code?
    In C# projects: SolnExplorer|Project|Properties|Debug|Enable unmanaged code debugging = TRUE(Checked)
    In C/C++ projects: SolnExplorer|Properties|Configuration Properties|Debugging|Debugger Type = Mixed

  • Are files being put where you think they are? I use a single bin\debug directory for collecting all project DLL's and PDB's.
    In the C# projects: SolnExplorer|Project|Properties|Build|Output Path = ..\bin\debug
    In C/C++ projects: SolnExplorer|Project|Properties|ConfigProp|Linker|OutputFile = ..\bin\debug\$(TargetName)$(TargetExt)

  • Are old files getting in the way? Check the timestamps on all the output files in the bin directory. Make sure they are as of the last rebuild.
    Some people advise blowing away all the bin and obj directories. This may be worthwhile just to see that old files aren't laying about. Checking the time and date stamps should do just as well.

  • Has the DLL been loaded? If the Breakpoints are disabled, it may be because the DLL has not been loaded yet. Check Menu|Debug|Windows|Modules.
    Look for the dlls in the module name.
    In the same Modules window make sure files are loading from the correct path.
    If an assembly is shared among several programs, it can be loaded from the GAC.
    -->Note: You can preload the C/C++ DLL before it is required. Use: IntPtr lpDLL = LoadLibrary(myLibraryName);

Sign up to request clarification or add additional context in comments.

5 Comments

Nice list, if I may add another after struggling with the same issue tonight, ensure that the C++ project, if it has CLR support, does not target a framework higher than that of the managed C# project; the symbols will 'load' and appear as such in the modules list but will not be utilized by the breakpoints/source file, failing with the 'Symbols not loaded' error which leads you down the wrong path!
I'll throw in additional answer in case someone will come by looking for solution to this kind of problem: If you are attaching a debugger through Debug>Attach To Process, before clicking "Attach" in the "Attach to Process" dialog, make sure to select the appropriate code type to which the debugger can be attached.
You are my hero! Thank you for the beautiful list! Got me going again.
Debugger type "mixed" was my issue, running a C++ project with a .NET dll. +1
BEAUTIFUL list :). You saved me a TON of frustration :).
0

I have a Windows Service in C# with a C++ DLL. The problem I saw was what Max noted:

  • The DLL worked, but never showed up in the Modules window.

I have done a lot of searching and this is a nice list which matches with information from many other sources.

To make ikh's note explicit:

  • "Auto" did not work for me, but explicitly setting "Native" and "Managed" code in the Attach dialog worked.

Comments

0

Here is my fifty cent. In my case it appeared that the pdb files of my c++/cli projects were not updated anymore, while the pdb files of my c# projects were. This probably rendered them invalid and made the debugger fail to load them.

I remembered to have moved the source base of my project. After a little bit of grepping it occurred to me that some absolute path issue might be the problem. Running a git clean -dfx solved the problem for me.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.