[ACCEPTED]-Why does my C# debugger skip breakpoints?-debugging

Accepted answer
Score: 31

My debugging checklist:

  • Make sure your attaching to the process using the correct code type - if your process has both unmanaged and managed code then dont rely on "auto" to work for you, explicitly state what sort of code your trying to debug
  • Goto the modules window (Debug -> Windows -> Modules, you may need to enable it in the "Customize..." menu
  • Check to make sure that the assembly your trying to debug has been loaded, and that symbols have been loaded - if they haven't been loaded then right click on that module and select "load symbols"
  • Open your code file and place your breakpoint - if it appears with the little warning symbol then look and see what it says,
  • You might need to goto "tools -> options - > debugging -> general" and untick "Enable Just My Code (Managed Only)"
  • You might also want to uncheck "Require source files to exactly match the original version", if you think your sources might be slightly out (beware however, as this can lead to you debugging with completely the wrong sources, which can be very confusing)

On certain cases 8 you might find that your module doesn't 7 get loaded at the point where you attach 6 your debugger (for example if you have some 5 sort of plug in archetecutre, and plugin 4 assemblies are only loaded when you first 3 use them). In these cases all you can do 2 is try and make sure everything is prepared 1 ready for when the module is loaded.

Score: 12

Make sure optimizations are disabled (this 3 is the defaut for the Debug configuration, but 2 they are enabled in Release configuration). Compiler 1 optimizations can mess with the debugger...

Score: 5

Are you sure that it compiled correctly? It 4 sounds to me like you're debugging against 3 a previous version, which can happen if 2 the build fails (perhaps a code bug, perhaps 1 the files are readonly).

Score: 2

If entire methods are being skipped, look 4 at the source and see if the System.Diagnostics.DebuggerStepThroughAttribute 3 attribute is present.

Despite the name, it 2 PREVENTS the debugger from stepping through 1 the method.

Score: 2

This worked for me in VS 2017, Go to Tools 3 > Options then under the Options Window 2 go to the Debugging section. Enable - "Enable 1 .NET Framework source stepping"

Score: 1

This sounds like your source code is out 8 of sync with the PDB files. The easiest 7 solution is to clean the solution (which 6 deletes all your dlls from the bin folder). Recompile, and 5 then try stepping through again.

If it still 4 fails, try closing the solution and deleting 3 the "obj" folders. And then try again.

And also check you are compiling in debug mode - something 2 I've done often ("why isn't it stepping 1 through?!") not getting break point

Score: 1

If at least sometimes the break point is 14 hit it means that all the settings are most 13 probably OK.

The missing hits may be caused 12 by some side-effects, for example: property 11 evaluation by the debugger (at least VS 10 skips the breakpoints during the property 9 evaluation for debugger) or some spying 8 tools (but these are usually catch by debugger).

If 7 you think this may be the case, turn off 6 the spying tools and disable the property evaluation by the debugger.

This may be sometimes 5 not enough, for example: If your property 4 returns a collection, displaying e.g. a 3 Count() will evaluate the property - so remove 2 also all references of property from the 1 watch windows, etc.

Score: 1

Disabling "Project Properties/Build/Optimize 1 code" worked for me.

Score: 1

@Justin's answer above was super helpful. I 1 would add one thing to the list.

  • Check to make sure you're running in debug and that your debug preferences have "Optimize code" unchecked. See below:

General run setting Debug SettingsRelease Settings

Score: 1

Also make sure that the code you're trying 7 to debug is running in the same process 6 as the main executable. I just wasted a 5 half hour figuring that one out - the breakpoint 4 wasn't hitting because the code of interest 3 had been spun up in a child process instead 2 of being called directly (the program in 1 question has two different modes of operation).

Score: 0

If you're getting this kind of error:

The 8 current .NET SDK does not support targeting 7 .NET Core 2.1. Either target .NET Core 6 2.0 or lower, or use a version of the .NET 5 SDK that supports .NET Core 2.1. DCR_Parser

Right 4 click on the project in solution explorer 3 and click on Properties. Under the Application 2 tab go to Target framework .NET Core 2.0. And 1 save.

More Related questions