title: Asp.NET Core 3.1 and Swashbuckle.AspNetCore.Swagger
body: <p>I updated my asp.net core app to v3.1 and updated my Swagger form v5.04 rc to v5.0, and everything stopped to work. The API is working, but I can't generate swagger file, and I was able.</p>
  
  <p>Here is my swagger configuration.</p>
  
  <pre><code>public static class SwaggerConfig
      {
          [Obsolete]
          public static void ConfigureSWAGGER(this IServiceCollection serviceColletion)
          {
              if (serviceColletion == null)
              {
                  throw new ArgumentNullException(nameof(serviceColletion));
              }
  
              // Use http://localhost:5000/swagger/ui/index to inspect API docs
              serviceColletion.AddSwaggerGen(x =&gt;
              {
                  x.SwaggerDoc(Constatns.BackofficeSwaggerGroup, new OpenApiInfo { Title = "Portal Nekretnine - Backoffice", Version = Constatns.BackofficeSwaggerGroup });
                  x.SwaggerDoc(Constatns.PublicSwaggerGroup, new OpenApiInfo { Title = "Portal Nekretnine - Public", Version = Constatns.PublicSwaggerGroup });
  
                  // This code allow you to use XML-comments
                  string xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                  string xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                  if (File.Exists(xmlPath))
                  {
                      x.IncludeXmlComments(xmlPath);
                  }
  
                  x.AddSecurityDefinition
                  (
                      "Bearer",
                      new OpenApiSecurityScheme
                      {
                          In = ParameterLocation.Header,
                          Description = "Please enter token into the field",
                          Name = "Authorization",
                          Type = SecuritySchemeType.ApiKey
                      }
                  );
              });
          }
  
          public static void UseSWAGGER(this IApplicationBuilder applicationBuilder)
          {
              // Enable middleware to serve generated Swagger as a JSON endpoint.
              applicationBuilder.UseSwagger();
  
              // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
              // specifying the Swagger JSON endpoint.
              applicationBuilder.UseSwaggerUI(x =&gt;
              {
                  x.SwaggerEndpoint($"/swagger/{Constatns.BackofficeSwaggerGroup}/swagger.json", "Portal Nekretnine - Backoffice");
                  x.SwaggerEndpoint($"/swagger/{Constatns.PublicSwaggerGroup}/swagger.json", "Portal Nekretnine - Public");
              });
          }
      }
  </code></pre>
  
  <p>And this is my startup.cs</p>
  
  <pre><code>public partial class Startup
      {
          public IConfiguration Configuration { get; }
  
          public Startup(IConfiguration configuration, IWebHostEnvironment env)
          {
              Configuration = configuration;
  
              if (env.IsDevelopment())
              {
                  IConfigurationBuilder builder = new ConfigurationBuilder()
                                                                          .SetBasePath(env.ContentRootPath)
                                                                          .AddJsonFile($"appsettings.development.json", optional: true)
                                                                          .AddEnvironmentVariables();
  
                  Configuration = builder.Build();
              }
              else
              {
                  IConfigurationBuilder builder = new ConfigurationBuilder()
                                                                          .AddJsonFile($"appsettings.production.json", optional: true)
                                                                          .AddEnvironmentVariables();
  
                  Configuration = builder.Build();
              }
          }
  
          // This method gets called by the runtime. Use this method to add services to the container.
          [System.Obsolete]
          public void ConfigureServices(IServiceCollection services)
          {
              SetServices(services);
  
              services.ConfigureCOMPRESSION();
  
              //disable built in model validator
              services.Configure&lt;ApiBehaviorOptions&gt;(options =&gt;
              {
                  options.SuppressModelStateInvalidFilter = true;
              });
  
              services.AddMvcCore(options =&gt;
                              {
                                  //Validate model
                                  options.Filters.Add(typeof(ValidateModelAttribute));
  
                                  // Add "Cache-Control" header
                                  options.Filters.Add(typeof(CacheControlFilter));
  
                                  // Add custom binder provider for mapping json object form multipart/form-data
                                  options.ModelBinderProviders.Insert(0, new JsonModelBinderProvider());
                              })
                              .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
                              .AddApiExplorer();
  
              services.AddControllers()
                              .AddNewtonsoftJson(options =&gt;
                              {
                                  options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
                                  options.SerializerSettings.Converters.Add(new JsonDateConverter());
                                  options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                                  options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
  #if DEBUG
                                  options.SerializerSettings.Formatting = Formatting.Indented;
  #else
                                  options.SerializerSettings.Formatting = Formatting.None;
  #endif
                              });
  
              services.Configure&lt;ForwardedHeadersOptions&gt;(options =&gt;
              {
                  options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
              });
  
              services.ConfigureCookieAuthentication();
              services.ConfigureAUTH(Configuration);
  
              services.ConfigureCORS();
  
              services.ConfigureSWAGGER();
              services.AddSwaggerGenNewtonsoftSupport(); // explicit opt-in - needs to be placed after AddSwaggerGen()
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              else
              {
                  app.UseHsts();
              }
  
              app.UseRouting();
  
              app.UseCOMPRESSION();
  
              app.UseAUTH();
              app.UseAuthorization();
  
              app.UseCORS();
              app.UseSWAGGER();
  
              app.UseHttpStatusCodeExceptionMiddleware();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllers();
              });
          }
      }
  </code></pre>
  
  <p>and an example of my controllers:</p>
  
  <pre><code>[ApiController]
  public class SecurityController : ControllerBase
  {
  
          [ApiExplorerSettings(GroupName = Constatns.PublicSwaggerGroup)]
          [SwaggerOperation(OperationId = "registerVisitor")]
          [HttpPost("api/register/visitor")]
          [ValidateModel]
          [AllowAnonymous]
          [ProducesResponseType((int)HttpResponseType.OK, Type = typeof(TokenResponse))]
          [ProducesResponseType((int)HttpResponseType.BadRequest)]
          [Produces("application/json")]
          public async Task&lt;TokenResponse&gt; RegisterVisitor([FromBody] RegisterVisitorRequest data)
          {}
  }
  </code></pre>
  
  <p>The error that I am getting are:</p>
  
  <p><em>fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
        An unhandled exception has occurred while executing the request.
  System.MissingMethodException: Method not found: 'Void Microsoft.OpenApi.Writers.OpenApiJsonWriter..ctor(System.IO.TextWriter)'.
     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.RespondWithSwaggerJson(HttpResponse response, OpenApiDocument swagger)
     at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine&amp; stateMachine)
     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.RespondWithSwaggerJson(HttpResponse response, OpenApiDocument swagger)
     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
     at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)</em></p>
  
  <p>thnx</p>