Skip to content
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
218 lines (146 sloc) 7.42 KB
layout author title date img desc categories tags interesting toc
Wouter Van Schandevijl
Debugging in Visual Studio
2019-02-23 16:00:00 -0800
We obviously never encounter bugs in our code. Still, should you ever need to debug, use these shortcuts so that it may be over soon.
url desc
Official Visual Studio Debugger Tutorial
title icon

Basic Shortcuts

{: .hide-from-excerpt}

{% include kbd k="F5" l="Start debugging" %} {% include kbd k="Control+F5" l="Start without debugging" %} {% include kbd k="Shift+F5" l="Stop debugging" %} {% include kbd k="Control+Shift+F5" l="Stop, rebuild and start debugging" %} {% include kbd k="Control+Alt+P" l="Attach to process" %}
{% include kbd k="Control+Alt+Break" l="Break (Debug > Break All)" %} {% include kbd k="F10" l="Step over" %} {% include kbd k="F11" l="Step into" %} {% include kbd k="Shift+F11" l="Step out" %} {% include kbd k="Control+F10" l="Run to cursor" %} {% include kbd k="Control+Shift+F10" l="Set next statement" %} {% include kbd k="Alt+Num *" l="See current statement" %}

Enable "Edit & continue" in Tools > Options > Debugging.
Other interesting settings:

  • Step over properties and operators (Managed only)
  • Just My Code (Enable to step over system, framework and other non-user calls)


{% include kbd k="Control+Alt+E" l="Control on which exceptions to break with the Exceptions window" %}

{% include kbd k="Control+Alt+B" l="Breakpoints window" %} {% include kbd k="F9" l="Toggle breakpoint" %} {% include kbd k="Control+F9" l="Enable/Disable breakpoint" %} {% include kbd k="Control+Shift+F9" l="Delete all breakpoints" %}

{% include kbd k="Control+B" l="New function breakpoint dialog" %} Useful when you want to add a breakpoint to every method with a specific name.

{% include kbd k="Alt+F9, C" l="Breakpoint condition" %} {% include kbd k="Alt+F9, L" l="Breakpoint label" %} Assigning labels to breakpoints could be handy together with the export/import functionality?

Breakpoints in `DEBUG` mode only: ```c# using System.Diagnostics; Debug.Fail(); Debug.Assert(true, "Conditional break"); ```


When you need to do some calculations for your assertions put it in a method decorated with the ConditionalAttribute("DEBUG").


Hover over a variable to see its value. Double click on it to change its value. Override ToString() or use the DebuggerDisplayAttribute() to display something better than GetType().FullName for your own classes.

class Counter
    public int count = 4;

    public int[] y => new[] {1, 2, 3};

More control with DebuggerTypeProxy:

Use this attribute when you need to significantly and fundamentally change the debugging view of a type, but not change the type itself. {: .notice--info}


{% include kbd k="Shift+F9" l="QuickWatch window for variable on cursor (blocking)" %} {% include kbd k="Control+Alt+C" l="Call stack window" %} {% include kbd k="Control+Alt+W, 1-4" l="Watch windows 1-4" %} {% include kbd k="Control+Alt+A" l="Command window" %}

Locals and Autos

Open from menu:

  • Debug > Windows > Locals
  • Debug > Windows > Autos

Can see member return values in the Autos window.
Text in red: variable value changed since last evaluation.

Output Window

Menu: Debug > Windows > Output
Control what is written to the Output Window with Tools > Options > Debugging > Output Window

Debug.WriteIf(true, "msg");
Debug.WriteLineIf(false, "msg");

Immediate window

{% include kbd k="Control+Alt+I" l="Immediate window" %}

Can access local variables and call methods. Even Linq queries are possible here.


One of my favourite bloggers, Phil Haack created the Visual Studio visualizer Encourage.

{% include github-stars.html url="haacked/encourage" desc="A bit of encouragment added to Visual Studio" %}


ReadableExpressions (download)
{% include github-stars.html url="agileobjects/ReadableExpressions" desc="Readable views of Expression Trees" %}

**DataTable Visualizer** ([download]( {% include github-stars.html url="MgSam/DataTableVisualizer" desc="A non-modal, dockable, searchable DataTable visualizer" %}
**Image Visualizer** ([download]( {% include github-stars.html url="aberus/ImageVisualizer" %}
**Entity Visualizer** ([download]( {% include github-stars.html url="kpol/EntityVisualizer" desc="Display SQL source code generated by Entity Framework" %}
**LINQBridgeVs** ([download]( {% include github-stars.html url="codingadventures/LINQBridgeVs" desc="Bridge between a Visual Studio debugging session and LINQPad." %}
Not open source: - **Mole** ([download]( - **DevArt LINQ Insight Express ORM Profiler** ([download](

New in Visual Studio

Visual Studio 2017

Run to click:
Run to click

Visual Studio 2019

  • Promises "significant" performance improvements in stepping
  • Yipiee, they added search to Autos, Locals and Watch windows! (Options > Debugging > Search)
  • They also managed to cut 25px from the title bar and still make it look pretty slick.
You can’t perform that action at this time.