CodexBloom - Programming Q&A Platform

Visual Studio 2022 - Debugging guide with .NET 6 Minimal API and Swagger Configuration

👀 Views: 71 💬 Answers: 1 📅 Created: 2025-06-08
visual-studio dotnet-6 swagger C#

Could someone explain I've searched everywhere and can't find a clear answer. I'm having trouble debugging my .NET 6 Minimal API project in Visual Studio 2022. After adding Swagger for API documentation, I noticed that when I try to hit the endpoints, the debugger doesn't seem to hit any breakpoints. The requests return a 200 OK status, but there's no execution hitting my controller methods, which makes it difficult to troubleshoot the logic. Here's how I set up my `Program.cs`: ```csharp var builder = WebApplication.CreateBuilder(args); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(); } app.MapGet("/api/values", () => new[] { "value1", "value2" }); app.Run(); ``` I've set my project to launch with the debugger attached, and I've tried cleaning and rebuilding the solution multiple times. I also ensured that the build configuration is set to 'Debug'. However, breakpoints in the `MapGet` method are completely ignored even though the API responds successfully. I also checked the output console for any logs during the request but didn’t find anything unusual. Any suggestions on what could be going wrong or if there's a configuration that I might be missing? Thanks in advance! I'm working with C# in a Docker container on Ubuntu 20.04. Thanks for your help in advance! This is for a microservice running on CentOS. This is my first time working with C# 3.9. Is there a better approach? Any help would be greatly appreciated!