Search code examples
c#asp.net-coreswaggerswashbuckle.aspnetcore

Was trying to set up Swagger for my .net core 7.0 project but it gives "Fetch error NetworkError when attempting to fetch resource" on opening


Most of the controllers have custom routing and APIs work when I fetch them through postman

Also have added the following for Swagger in my Startup.cs

services.AddSwaggerGen(options =>
        {
            options.SwaggerDoc("v1", new OpenApiInfo
            {
                Version = "v1",
                Title = "ToDo API",
                Description = "An ASP.NET Core Web API for managing ToDo items",
                TermsOfService = new Uri("https://example.com/terms"),
                Contact = new OpenApiContact
                {
                    Name = "Example Contact",
                    Url = new Uri("https://example.com/contact")
                },
                License = new OpenApiLicense
                {
                    Name = "Example License",
                    Url = new Uri("https://example.com/license")
                }
            });
        });

Also

if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
                options.RoutePrefix = string.Empty;
            });

        }

The web page loads but the APIs do not webpage

After Inspecting the URL URL

The Logs

2023-05-17 12:44:14.5197 Error Error parsing layout aspnet-request-statuscode will be ignored. Exception: System.ArgumentException: LayoutRenderer cannot be found: 'aspnet-request-statuscode'. Is NLog.Web not included?
   at NLog.Config.Factory`2.CreateInstance(String itemName)
   at NLog.Layouts.LayoutParser.GetLayoutRenderer(ConfigurationItemFactory configurationItemFactory, String name, Nullable`1 throwConfigExceptions)

Already have the following in my nlog.config

  <extensions>
<add assembly="NLog.Web.AspNetCore"/></extensions>

Solution

  • Fixed it, apparently it was because I had a few non-action methods inside the some of the controllers which caused this, fixed this by adding [ApiExplorerSettings(IgnoreApi = true)] on top of the non action methods.