How to debug .NET source code in Visual Studio

When you’re using the Visual Studio debugger to step through your code, sometimes it’s useful to be able to step into the .NET source code. I had to do this recently to figure out why my ASP.NET Core code wasn’t behaving as expected. You can enable .NET source code debugging with the following steps: Now … Read more

Visual Studio – How to use conditional breakpoints

Breakpoints cause execution to pause when you’re running the debugger. This is referred to as breaking, and it allows you to look at the current state of things for debugging purposes. In some cases, you may want to use a conditional breakpoint to only break execution when certain conditions are met (ex: break when name … Read more

C# – Conditional compilation

You can exclude specific code from being compiled by using conditional compilation symbols. There are a few predefined symbols that support common scenarios – conditional compilation based on target framework (ex: .NET 5 vs .NET Core 3.1) and based on build configuration (Debug vs Release). In addition, you can add your own symbols to handle … Read more

Starting the Visual Studio debugger when Attach to Process doesn’t work

Problem You’re trying to debug a program with Visual Studio but Attach to Process does not work. Most likely you’re loading your code through some third-party process (like Excel), and when you try to use Attach to Process it simply doesn’t work. Solution Instead of trying to use Attach to Process, you can launch a … Read more