title: ASP.Net Core + Swagger - Actions require an explicit HttpMethod binding for Swagger 2.0
body: <p>I have a project <em>MyProject.Api</em> with following structure:</p>
  
  <pre><code>Controllers/
  - Api/
    - UsersController.cs
  - HomeController.cs
  Startup.cs
  </code></pre>
  
  <p>where <strong>HomeController.cs</strong> looks like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace MyProject.Api.Controllers
  {
      public class HomeController : Controller
      {
          private readonly IHostingEnvironment _hostingEnvironment;
  
          public HomeController(IHostingEnvironment hostingEnv) {...}
  
          [HttpGet]
          public async Task&lt;IActionResult&gt; Index() {...}
  
          [HttpGet("sitemap.xml")]
          public IActionResult SiteMap() {...}
  
          [HttpGet("error")]
          public IActionResult Error() {...}
      }
  }
  </code></pre>
  
  <p>and <strong>UsersController.cs</strong> looks like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace MyProject.Api.Controllers.Api
  {
      [Route("api/[controller]")]
      public class UsersController : Controller
      {
          private readonly ApiHelper&lt;UsersController&gt; _apiHelper;
          private readonly IUserService _userService;
  
          public UsersController(ILogger&lt;UsersController&gt; logger, IUserService userService) {...}
  
          [HttpPost("login")]
          public async Task&lt;JsonResult&gt; Login([FromBody] LoginRequest request) {...}
  
          [HttpPost("register")]
          public async Task&lt;JsonResult&gt; Register([FromBody] RegisterRequest request) {...}
  
          [HttpGet("renew")]
          [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
          public async Task&lt;JsonResult&gt; Renew() {...}
      }
  }
  </code></pre>
  
  <p>and <strong>Startup.cs</strong>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>
  namespace MyProjet.Api
  {
      public class Startup
      {
          private IConfiguration Configuration { get; }
  
          public Startup(IConfiguration configuration) {...}
  
          public void ConfigureServices(IServiceCollection services)
          {
              ...
  
              services.AddSwaggerGen(c =&gt; c.SwaggerDoc("v1", new Info {Title = "Web Api Docs", Version = "v1"}));
          }
  
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              ...
  
              app.UseSwagger();
              app.UseSwaggerUI(c =&gt; { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); });
              app.MapWhen(x =&gt; !x.Request.Path.Value.StartsWith("/swagger", StringComparison.OrdinalIgnoreCase), builder =&gt;
              {
                  builder.UseMvc(routes =&gt;
                  {
                      routes.MapSpaFallbackRoute(
                         "spa-fallback",
                          new {controller = "Home", action = "Index"});
                  });
              });
          }
      }
  }
  </code></pre>
  
  <p>when I load <code>/swagger</code> the UI loads successfully, but with following error:</p>
  
  <pre><code>Fetch error
  Internal Server Error /swagger/v1/swagger.json
  </code></pre>
  
  <p>and with this error on the server side</p>
  
  <pre class="lang-cs prettyprint-override"><code>System.NotSupportedException: Ambiguous HTTP method for action - WebEssentials.AspNetCore.Pwa.PwaController.ServiceWorkerAsync (WebEssentials.AspNetCore.Pwa). Actions require an explicit HttpMethod binding for Swagger 2.0
     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreatePathItem(IEnumerable`1 apiDescriptions, ISchemaRegistry schemaRegistry)
     at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
     at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath, String[] schemes)
     at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
     at Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.SpaServices.Webpack.ConditionalProxyMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
     at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
  </code></pre>
  
  <p>but all methods have unique route, unique name and their HTTP methods are explicitly bound. I've tried adding <code>[Route("")]</code> to the <em>HomeController.cs</em>, but that did not work either.</p>
  
  <p>What am I doing wrong?</p>