A component of ASP.NET for creating RESTful web services that support HTTP-based communication between clients and servers.
The screenshot shows that Swagger UI loads, but it can’t fetch the OpenAPI document at /swagger/v1/swagger.json (NetworkError). This usually means the API is running and reachable, but the Swagger endpoint itself is misconfigured or not available at that path.
Typical causes in ASP.NET Core Web API:
- Swagger middleware not mapped for the environment
- In
Program.cs, Swagger is often only enabled in Development:
If the app is running under a different environment (e.g.,if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); }Production),/swagger/v1/swagger.jsonwon’t exist, and Swagger UI will show a network error.- Fix: Either run the app with
ASPNETCORE_ENVIRONMENT=Developmentor moveapp.UseSwagger(); app.UseSwaggerUI();outside theIsDevelopmentblock if Swagger should always be available.
- In
- Wrong route or document name
- If
SwaggerGenis configured with a different document name or route, the UI might still be pointing to/swagger/v1/swagger.jsonwhile the actual JSON is at another URL. - Fix: Ensure the document name in
AddSwaggerGenmatches the one used inUseSwaggerUI, for example:
builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new() { Title = "WebApp1", Version = "v1" }); }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApp1 v1"); }); - If
- HTTPS/port mismatch
- If the app is actually listening on a different port or scheme than the one Swagger UI is using, the fetch will fail.
- Fix: Confirm the app is running on
https://localhost:7060and that no reverse proxy or different port is used. Adjust launch profile or Swagger endpoint accordingly.
- Middleware order or startup failure
- If there’s an exception during startup before
UseSwaggerruns, the JSON endpoint won’t be available even though the browser still shows a cached or partial UI. - Fix: Check application logs/console output for startup errors and ensure
app.UseSwagger()is called beforeapp.UseAuthorization()/app.MapControllers().
- If there’s an exception during startup before
Because direct calls to the API work, focus on verifying that the Swagger JSON endpoint exists and matches the URL configured in UseSwaggerUI, and that Swagger middleware is enabled for the environment where the app is running.
References:
- Troubleshoot Web API2 apps that work in Visual Studio and fail on a production IIS server
- Call a web API from ASP.NET Core Blazor
- Authorization Issue with AddSecurityRequirement for OAuth2 in .NET 10 (C# 14) Swagger Configuration - Microsoft Q&A
- Swagger AddSecurityRequirement Fails After Migrating from .NET 8 to .NET 10 — 401 Unauthorized on [Authorize] Endpoints - Microsoft Q&A