BREAKPOINT

What Is a Breakpoint in Visual Studio? Complete C# and ASP.NET Core Debugging Guide (2026)

Introduction

Debugging is an essential skill for every software developer. While developing applications using C#, ASP.NET MVC, ASP.NET Core, or Web API, developers frequently need to identify errors, inspect variable values, and understand how their code executes.

Visual Studio provides a powerful debugging feature called a breakpoint.

A breakpoint allows developers to pause program execution at a specific location and inspect the application's current state.

In this tutorial, you will learn what a breakpoint is, how to use breakpoints in Visual Studio, different types of breakpoints, debugging shortcuts, and how to troubleshoot breakpoints that are not working.

1. What Is a Breakpoint in Visual Studio?

A breakpoint is a debugging marker that instructs the debugger to pause program execution when a specified location or condition is reached.

Breakpoints allow developers to examine variables, inspect objects, evaluate expressions, and identify problems without changing the application's business logic.

For example, consider the following C# code:

int number1 = 10;
int number2 = 20;

int result = number1 + number2;

Console.WriteLine(result);

If you place a breakpoint on the line:

int result = number1 + number2;

Visual Studio pauses before executing that statement when the breakpoint is reached.

You can then inspect the values of number1 and number2.

Key point: A breakpoint does not permanently stop the application. Execution can continue when you press F5.

2. Why Do We Use Breakpoints?

Breakpoints help developers:

  1. Identify errors in application logic.

  2. Inspect variable and object values.

  3. Understand the flow of program execution.

  4. Debug conditional statements and loops.

  5. Analyze exceptions and unexpected results.

  6. Debug API requests and database operations.

  7. Troubleshoot issues without adding unnecessary Console.WriteLine() statements.

Breakpoints are especially useful when working with complex ASP.NET Core applications containing controllers, services, repositories, and database operations.

3. How to Set a Breakpoint in Visual Studio

Follow these steps to create a breakpoint:

Step 1: Open your C# or ASP.NET project in Visual Studio.

Step 2: Open the source code file where you want to pause execution.

Step 3: Click the left margin next to the executable line.

Step 4: Alternatively, place the cursor on the line and press F9.

Step 5: Press F5 to start debugging.

Step 6: Execute the application functionality that reaches the breakpoint.

When the breakpoint is hit, Visual Studio pauses execution and highlights the current statement.

A standard enabled breakpoint is generally displayed as a red circle in the editor margin.

4. Example: Using a Breakpoint in C#

Consider the following C# method:

public static int CalculateTotal(int price, int quantity)
{
    int total = price * quantity;

    return total;
}

Call the method:

int result = CalculateTotal(500, 3);

Console.WriteLine(result);

Expected output:

1500

To debug this code:

  1. Set a breakpoint on int total = price * quantity;.

  2. Start debugging using F5.

  3. When execution pauses, inspect price and quantity.

  4. Press F10 to execute the calculation.

  5. Inspect the value of total.

  6. Press F5 to continue execution.

This technique helps verify calculations and locate incorrect values.

5. Types of Breakpoints in Visual Studio

Visual Studio supports several breakpoint features for different debugging scenarios.

A. Line Breakpoint

A line breakpoint pauses execution when the debugger reaches a particular executable statement.

Example:

int a = 10;
int b = 20;

int sum = a + b;

Set a breakpoint on the calculation line to inspect the values before execution.

B. Conditional Breakpoint

A conditional breakpoint pauses execution only when a specified condition evaluates to true.

This is useful when debugging loops or large collections.

Example:

for (int i = 1; i <= 100; i++)
{
    Console.WriteLine(i);
}

Suppose you want execution to pause only when i equals 50.

Right-click the breakpoint, open its conditions settings, and enter:

i == 50

The debugger pauses when the condition is satisfied.

Benefit: You do not need to manually step through all 50 iterations.

C. Hit Count Breakpoint

A hit count breakpoint allows you to control when a breakpoint pauses based on how many times it has been reached.

For example, you can configure a breakpoint to pause when its hit count reaches a specified number.

This is useful for debugging repeatedly executed methods and loops.

D. Function Breakpoint

A function breakpoint can pause execution when a specified function is entered.

For example:

public void ProcessOrder()
{
    Console.WriteLine("Processing Order");
}

You can configure a function breakpoint for the relevant method through the Breakpoints window.

Function breakpoint support and naming requirements depend on the debugger and language.

E. Tracepoint

A tracepoint is a breakpoint configured to perform an action, such as displaying a message, without necessarily pausing execution.

For example, you can configure a tracepoint to log information when a particular statement is reached.

Tracepoints are useful for investigating execution flow without stopping at every occurrence.

6. Important Visual Studio Debugging Shortcuts

ShortcutDescription
F5Start or continue debugging
Ctrl + F5Start without debugging
Shift + F5Stop debugging
F9Toggle breakpoint
F10Step Over
F11Step Into
Shift + F11Step Out
Ctrl + Alt + BOpen Breakpoints window
Ctrl + Alt + W, 1Open Watch 1 window
Ctrl + Alt + IOpen Immediate Window

Shortcuts may vary depending on the Visual Studio keyboard configuration.

7. Difference Between F5, F10, and F11

Understanding these three shortcuts is essential for debugging C# applications.

KeyFunctionExplanation
F5ContinueRuns until the next breakpoint or another debugger stop
F10Step OverExecutes the current statement without stepping into called methods
F11Step IntoSteps into a called method when debugging information is available

Example:

int result = AddNumbers(10, 20);

Console.WriteLine(result);

static int AddNumbers(int a, int b)
{
    return a + b;
}

If execution is paused on the AddNumbers() call:

  • Pressing F10 executes the call without entering the method.

  • Pressing F11 steps into AddNumbers() when supported.

  • Pressing F5 continues execution until the next debugger stop.

8. How to Debug an ASP.NET Core Web API Using Breakpoints

Breakpoints are commonly used to debug ASP.NET Core Web API controllers.

Example: ProductController.cs

using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("api/[controller]")]
public class ProductController : ControllerBase
{
    [HttpGet("{id:int}")]
    public IActionResult GetProduct(int id)
    {
        var product = new
        {
            ProductId = id,
            ProductName = "Laptop",
            Price = 45000
        };

        return Ok(product);
    }
}

Debugging Steps

Step 1: Open ProductController.cs.

Step 2: Set a breakpoint on:

var product = new

Step 3: Press F5 to run the ASP.NET Core application.

Step 4: Send a GET request to the API endpoint:

GET https://localhost:5001/api/product/101

Replace the example port with the HTTPS port configured for your application.

Step 5: Visual Studio pauses when the request reaches the breakpoint.

Step 6: Inspect the value of id.

Step 7: Press F10 to step through the code.

Step 8: Press F5 to continue execution.

Example JSON response:

{
  "productId": 101,
  "productName": "Laptop",
  "price": 45000
}

The exact JSON property casing depends on the application's serialization configuration.

9. How to Inspect Variable Values During Debugging

Visual Studio provides several tools for inspecting application state.

Locals Window

Displays local variables available in the current debugging context.

Watch Window

Allows developers to monitor specific variables or expressions.

For example:

price * quantity

Immediate Window

Allows developers to evaluate expressions while execution is paused.

Call Stack Window

Shows the chain of method calls that led to the current execution point.

DataTips

Hover over a variable while debugging to inspect its current value.

These tools make it easier to identify incorrect calculations, null references, and unexpected object states.

10. How to Remove or Disable Breakpoints

You can manage breakpoints using the editor or Breakpoints window.

Remove a breakpoint: Click its red circle or press F9 while the cursor is on the breakpoint line.

Disable a breakpoint: Use the breakpoint context menu or Breakpoints window to disable it without deleting it.

Manage all breakpoints: Open Debug → Windows → Breakpoints.

Delete all breakpoints: Use the Delete All Breakpoints command in Visual Studio.

Disabling a breakpoint preserves its configuration for later use.

11. Why Is My Breakpoint Not Working in Visual Studio?

Sometimes a breakpoint is not hit, or Visual Studio displays a warning indicating that the breakpoint cannot currently be bound.

Common reasons include:

ProblemPossible Solution
Application is not running under the debuggerStart using F5 or attach the debugger
Breakpoint is on a non-executable lineMove it to an executable statement
Source code does not match the running assemblyRebuild and deploy the correct version
Debug symbols are missingVerify PDB symbol loading
Wrong process is being debuggedAttach to the correct application process
Code path is not executedVerify that the relevant method is called
Release optimizations affect debuggingUse a Debug build when possible
Conditional breakpoint is falseCheck the condition and variable values

Example: Breakpoint Not Hit in ASP.NET Core

If a breakpoint inside a controller is not reached:

  1. Confirm that the API route is correct.

  2. Verify that the request reaches the expected endpoint.

  3. Check that Visual Studio is debugging the correct application.

  4. Verify that the latest source code has been built.

  5. Inspect loaded symbols using Debug → Windows → Modules, when available.

For applications hosted on IIS, confirm that the debugger is attached to the appropriate worker process and that you have permission to debug it.

12. Breakpoints vs Console.WriteLine vs Logging

FeatureBreakpointConsole.WriteLineStructured Logging
Pauses executionYes, when configured to breakNoNo
Inspect variables interactivelyYesNoNo
Requires debuggerYesNoNo
Suitable for production diagnosticsGenerally noLimitedYes
Best useInteractive debuggingSimple development outputApplication diagnostics and monitoring

For production ASP.NET Core applications, structured logging with ILogger is generally more appropriate than interactive breakpoints.

13. Best Practices for Using Breakpoints

  1. Set breakpoints near the code you need to investigate.

  2. Use conditional breakpoints when debugging large loops.

  3. Inspect variables before and after important calculations.

  4. Use the Call Stack window to understand method execution.

  5. Verify that debugging symbols match the running application.

  6. Use tracepoints when you want diagnostic messages without stopping execution.

  7. Avoid pausing live production applications unless you fully understand the operational impact.

  8. Use application logging and monitoring for production troubleshooting.

Frequently Asked Questions

What is a breakpoint in C#?

A breakpoint is a debugging marker that pauses execution at a specified statement or condition, allowing developers to inspect application state.

Which shortcut is used to set a breakpoint?

Press F9 to toggle a breakpoint in Visual Studio.

What does F5 do in Visual Studio?

F5 starts debugging or continues execution until another debugger stop occurs.

What is the difference between F10 and F11?

F10 steps over a method call, while F11 attempts to step into the called method.

Can we use breakpoints in ASP.NET Core Web API?

Yes. Breakpoints can be placed in controllers, services, middleware, repositories, and other executable C# code.

What is a conditional breakpoint?

A conditional breakpoint pauses execution only when a specified condition evaluates to true or another supported condition is satisfied.

Why does Visual Studio show a hollow breakpoint?

A hollow or warning-marked breakpoint can indicate that the debugger cannot currently bind the breakpoint, often because symbols are missing, source code does not match, or the relevant module has not loaded.

Do breakpoints affect application performance?

Breakpoints and debugger evaluation can introduce overhead. When execution pauses, the application may stop responding to affected requests until debugging continues.

Conclusion

Breakpoints are one of the most useful debugging features in Visual Studio.

They help C# and ASP.NET developers pause execution, inspect variable values, analyze method calls, and identify errors efficiently.

By learning line breakpoints, conditional breakpoints, hit counts, tracepoints, and debugging shortcuts such as F5, F9, F10, and F11, developers can troubleshoot applications more effectively.

Whether you are working with traditional ASP.NET MVC, ASP.NET Core, or Web API, mastering breakpoints is an essential part of becoming a productive .NET developer.

Official Microsoft Documentation


Comments