问题
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.
回答1:
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.
回答2:
I had this issue with an ASP.NET application. What I did to fix it was:
- Cleaned the application
- Cleaned the class library
- Restarted Visual Studio
- Ran the project
I suspect there was something going on with it generating and copying the symbols to the application when it was built.
来源:https://stackoverflow.com/questions/33835680/in-visual-studio-why-can-i-not-debug-a-referenced-class-library