Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error when publishing webAPI to Azure

I built my first API and am trying to publish to Azure.

I get the following error "Be sure that the Startup.cs for your application is calling AddSwaggerGen from within ConfigureServices in order to generate swagger file. Visit https://go.microsoft.com/fwlink/?LinkId=2131205&CLCID=0x409 for more information."

Failed to generate swagger file. Error dotnet swagger tofile

Here is my code from Startup.cs:

 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PeopleSearch v1"));
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}

Does anyone know what I am doing wrong?

like image 571
Dumbledore502 Avatar asked Dec 14 '20 20:12

Dumbledore502


1 Answers

I have been seeing so many questions regarding this issue but not even a single reliable answer. I tried almost all of the solutions with little to no success, the only thing which resolved it for me was the following

  • Delete bin, obj, and .config folders (.config is a folder, not a file)
  • Reopen the project and let the NuGet load in the background (it has removed all the NuGet refs)
  • Do a CLEAN and REBUILD

I am not sure if this is going to resolve the issue for anyone else but it did work for me so worth a try.

like image 133
Ali Avatar answered Nov 15 '22 03:11

Ali