Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Visual Studio, why can I not debug a referenced class library?

I know this probably sounds easy and that a lot of people have asked the same or similar questions. I have spent many hours on this, and none of the solutions work for me.

I have a solution that has two projects:

Project 1 is a Windows forms application that depends on Project 2.
Project 2 is a class library.

  • I have added a reference to Project 2 in Project 1. I selected Add Reference --> Projects, then checked the box for Project 2.
  • I set Project 1 as the startup project.
  • I have the profile set to Debug.
  • I have set both projects to generate full debug information and have verified that both projects are generating .pdb files.

When debugging, my breakpoints in Project 1 work fine. In Project 2 if I hover over a breakpoint it displays in infamous, "The breakpoint will not currently be hit. No symbols have been loaded for this document."

If, while debugging, I choose Modules from the Debug menu, the class library is not even listed as being loaded, so I don't even have the option to load them manually.

I left out details about language, Visual Studio version, target .NET framework because I have created test projects in C# and VB, targeted different versions of the .NET framework, and used three different versions of Visual Studio (2008, 2013, and 2015).

The only scenario that I have found under which I am able to debug a referenced library is when I created an MVC web application. It never works when I try it with a Windows forms application or a console application.

What am I missing here?

Thanks

Update I just did another test where I created a class library first, and then added a console application project to the solution (In previous tests I did it the other way around). I then added a reference to the class library project in the console application project. I was then able to debug both projects. Both the .exe for the console application and the .dll for the class library show up under Debug --> Windows --> Modules, whereas normally when I add the class library second, it does not show up here. Very strange. This however still does not solve my problem since I need this to work with an existing solution.

like image 935
joebedan Avatar asked Jan 26 '26 10:01

joebedan


2 Answers

I had a similar problem. I had to go to Tools > Options > Debugging and then uncheck "Enable Just My Code" and uncheck "Step over properties and operators (Managed only)"

like image 83
William Avatar answered Jan 28 '26 11:01

William


For some reason, sometimes when you first start debugging, a referenced class library does not show on the list of loaded modules. The breakpoints in the class library will also show white and say that they will not be hit because the symbols are not loaded.

But as it turns out, it will still hit the breakpoint and then the class library DLL does show in the modules list. It seems like it is not loading it until it actually uses it. Sometimes this is not the case. I cannot tell why sometimes it loads the class library DLL as soon as debugging starts and sometimes it doesn't.

like image 30
Thomas W. Avatar answered Jan 28 '26 12:01

Thomas W.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!