CodexBloom - Programming Q&A Platform

Visual Studio 2022 - how to to run ASP.NET Core Web API due to 'The connection was closed unexpectedly' scenarios

👀 Views: 95 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-13
asp.net-core visual-studio iis-express C#

I've searched everywhere and can't find a clear answer. I'm trying to configure I've been struggling with this for a few days now and could really use some help. I'm working with an scenario when trying to run my ASP.NET Core Web API project in Visual Studio 2022. The project builds successfully, but when I try to run it, I get the behavior message: 'The connection was closed unexpectedly'. This question occurs regardless of whether I'm using IIS Express or the Kestrel server. I've already tried restarting Visual Studio and cleaning the solution, but the scenario continues. Here's a snippet of my `launchSettings.json`: ```json { "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "MyWebAPI": { "commandName": "Project", "launchBrowser": true, "applicationUrl": "http://localhost:5000;https://localhost:5001", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } } ``` I've also checked the Event Viewer for any related logs, but couldn't find anything specific. Additionally, I ensured that my `appsettings.Development.json` file is correctly set up and includes the necessary configurations for logging. I have the following middleware in my `Startup.cs` file: ```csharp public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/behavior"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } ``` I'm also using .NET 6.0 and have confirmed that all my packages are up to date via NuGet Package Manager. Is there a specific setting or configuration I might be missing that would lead to this behavior? Any help would be appreciated! My development environment is Windows. I'd really appreciate any guidance on this. I'm working in a Windows 10 environment. Any advice would be much appreciated. I'm working in a CentOS environment.