1776
votes

A C# desktop application on the express edition worked, but then it didn't work 5 seconds later.

I tried the following:

  • Ensure debug configuration, debug flag, and full debug information are set on all assemblies.
  • Delete all bin and obj folders and all DLL files related to the project from my entire machine.
  • Recreate projects causing the problem from scratch.
  • Reboot.

I have two Windows Forms projects in the solution. One of them loads the debug information, one doesn't. They both refer to the assembly I'm trying to get debug information on in exactly the same way in the project file. Any ideas?


I want to add here, mostly for myself when I come back to review this question, that symbols are not loaded until the assembly is loaded, and the assembly is not loaded until it is needed. If the breakpoint is in a library that is only used in one function in your main assembly, the symbols will not be loaded (and it will show the breakpoint as not being hit) until that function is called.

30
When debugging, goto to the Debug, Windows, Modules view. This will show info about loaded modules and symbol status. You can right click a module and try to load the symbols from another location.Polyfun
Express edition does not have Modules view.Instance Hunter
Good point about assemblies not loaded until needed. The debugger will show that the breakpoint won't be hit, but the display will change/your breakpoint WILL be hit once the assembly is loaded. A cheesy workaround this UI issue would be to make a call to the assembly at program start to force the assembly to be loaded.Tim Coker
I had same issue and I noticed that for this build configuration I didn't have <DebugSymbols>true</DebugSymbols> under it in VS2015 I manually added it and it worked fine.kuskmen
Removing the .suo file might have solved this ugly problem at my projectRoland

30 Answers

1182
votes

Start debugging, as soon as you've arrived at a breakpoint or used Debug > Break All, use Debug > Windows > Modules. You'll see a list of all the assemblies that are loaded into the process. Locate the one you want to get debug info for. Right-click it and select Symbol Load Information. You'll get a dialog that lists all the directories where it looked for the .pdb file for the assembly. Verify that list against the actual .pdb location. Make sure it doesn't find an old one.

In normal projects, the assembly and its .pdb file should always have been copied by the IDE into the same folder as your .exe, i.e. the bin\Debug folder of your project. Make sure you remove one from the GAC if you've been playing with it.

543
votes

Check if you are not in release but in Debug.

When in debug:

First try rebuilding your project by right mouse click the project > Rebuild If that doesn't work, try a clean of the project (right mouse click on the project > clean)

If that didn't work check this:

  1. Right mouse click your project
  2. Select [Properties]
  3. Select the [Build] tab
  4. Make sure [Define DEBUG constant] and [Define TRACE constant] are checked
  5. Make sure [Optimize Code] is unchecked
  6. Click the [Advanced] button at the bottom of the Build tabpage
  7. Make sure that [Debug Info:] is set to [full]
  8. Click [OK] and rebuild the project ;-)

(step 6 generates the .pdb files, these are the debugging symbols)

285
votes

Just something simple to try - you may have tried it already. Right click the Solution in solution explorer, click "clean solution", this deletes all the compiled and temporary files associated with a solution.

Do a rebuild of the solution and try to debug again.

I've also had troubles with breakpoints multiple projects in a solution - some compiled as x86, some as x64.

263
votes

Disable the "Just My Code" option in the Debug/General settings.

155
votes

Cross posting this fix from Hans K that I found on the similar thread >> HERE <<:

Right click on solution --> Properties

Look under Common Properties --> Startup Project

Select multiple startup projects

select Start action on the projects you need to debug.

71
votes

The selected answer led me to fix my problem. But I need to do a few things more:

Even with "Debug" selected in the dropdown:

enter image description here

And in the project Properties > Build:

enter image description here

The Visual Studio was not loading symbols to a specific project. So in that dropdown I select "Configuration Manager" and saw that the settings to my web project was incorrect:

enter image description here

enter image description here

Then I set that to "Debug" and it started to generate the .pdb file. BUT I need to manually copy the PDB and DLL and put in the folder that VS was looking (here is where the selected answer helped me):

enter image description here

51
votes

Sometimes, even though it gives you this error, the breakpoint still gets hit, so just ignore the error. This happens fairly often in the Views of an MVC web app.

45
votes

Debug > Windows > Modules to see what modules were being loaded put me in the right direction.

In my case IIS Express seemed to be loading a different DLL from the temporary ASP.NET files.

The solution?

  1. Browse to C:\Users\<YOUR USER>\AppData\Local\Temp\Temporary ASP.NET Files\vs
  2. Delete everything in this directory!
43
votes

I was able to fix the error by simply setting the option in the 'Attach to Process' to 'Automatically determine the type of code to debug' option as shown in the attached screenshot.

Simply follow the steps below:

  • Go to Debug from the menu bar
  • Click on Attach to Process
  • Near the Attach to option, click on the Select button
  • The Select Code Type window will appear
  • Now select the option Automatically determine the type of code to debug and click the OK button.

Fixed Debugging Error

42
votes

Check if your .pbd file is missing in your bin/Debug folder. If it is then go to "Properties" of your project, selected "Build" and then "Advanced" at the bottom. Choose "full" under "Debug info" in the new window that appeared. This was my issue and solved it for me.

Showing where to find the setting

29
votes

In my case "Optimize Code" was checked in my project properties. This caused VS to see my assembly as "not my code", and in turn, it did not load symbols for it.

The solution was to uncheck this. Location of Optimize Code checkbox

29
votes

Just Check whether your solution is in Release Mode.

24
votes

Try running visual studio as an administrator within windows.

22
votes

In my case i am trying to debug in relase mode. Once i change it to debug mode. Its working

18
votes

Debug ->Options -> General -> Uncheck mark for "Enable Just My Code"

This worked for me.

17
votes

You need to enable "Generate debug info" in compiler settings

12
votes

Check your Solution Configuration drop down list. Make sure you select Debug, not Release.

10
votes

We found the cause of our problem. This code was using the "CodeBehind" attribute in the Page directive of the .aspx file instead of the "CodeFile" attribute (ASP.NET 2.0 and beyond). After days of desperation, a simple search and replace solved the problem.

10
votes

Option "Start debugging, Debug + Windows + Modules" does not exist in Microsoft Visual Studio Express 2013 edition.

Unchecking "Use Managed Compatibility Mode" in Tools Options Debugging fixes this.

9
votes

I tried everything mentioned above, but nothing worked. [Clean solution, and check for PDB files etc.]

Even publishing the same solution did not resolve the issue.

Then I went to back to what I usually do to resolve (fool this stubborn Visual Studio)

All I did was to make a deliberate change in code and publish the solution. Then I reverted the change and published again.

Voila [PDB files rid of evil spirits].. Not a smart resolution, but this did work.. :-|

9
votes

Webapplications (IIS Express) only:

  • Rightclick IIS Express Tray and close the IIS.
  • Clean Solution

IIS Tray

8
votes
  1. Clean solution and Rebuild
  2. Check the configuration is set to Debug
  3. Make sure that the PDB file is in the Debug folder it self
  4. From Debug menu click Enable All Break points
8
votes

Check are the following two setting the same in Visual Studio:

Right click test project, go to Properties, Build tab, and look at Platform target

Mine are all set to "Any CPU" so x64

enter image description here

On the Main Menu bar, go to Test, Test Settings, Default Processor Architecture

Mine was set to X86

enter image description here

Changing this to X64 to match above setting made the built in Visual Studio menu “Debug Test(s)” work and hit breakpoints that were previously ignored with the message “The breakpoint will not currently be hit. No symbols have been loaded for this document”.

Update:

For Visual Studio 2019 the menus have been moved around a bit: enter image description here

7
votes

None of those answers solved my problem. I tried another thing based on fact that the project with the stop wasn't in reality the loaded project. I found as Hans Passant wrote that the .dll where I want to stop debugger and the associoated .pdb files where copied near the .exe file. Those files have had an older date so I thought they wasn't updated in the runtime. I manually deleted them, Visual Studio create another pair AND put this new pair near the .exe. Now the breakpoins works !

Maybe Visual Studio cannot copy and REPLACE existing files (.dll and .pdb) near the .exe since there are another there. So if I deleted manually then VS could create new one near .exe.

I think that another changes (checks and so on - from the another answers) triggered something and Visual Studio copied and replaced the dll and pdb from the project folder to the folder near the exe, so that was a solution.

I think that the root cause of the problem is that the Visual Studio use another file in runtime, no the file from the project, with the stop.

Maybe this answer to help someone !

7
votes

I had similar issue and I did the following: Debug=>Options=>General => Remove the check mark for "Enable Just My Code" This worked for me..

6
votes

Things to check just to be clear: Make sure you have the configuration set to 'Debug' and not 'Release'. You can debug the startup project in 'Release' mode, but not a referenced class library.

6
votes

Project Properties (then select your build config) > Build Tab > Advanced... > Debug Info (dropdown)

Set to 'all' or 'pdb-only' then rebuild

6
votes

Instead of doing all these things just

Close and reopen

the solution it will fix the issue

6
votes

I know I'm years late, but I thought I'd done something wrong and followed the above steps then I realised I'd set the solution configuration to 'Release' by mistake :)

6
votes

This took me a while tried other options above and for some strange reason debugging stopped working.

Tool -> Options -> Debugging -> General -> (untick) "Require source files to exactly match the original version" option