Tuesday, September 1, 2020

ASP.NET Core Swagger error - Conflicting method/path combination

After adding a new method to a controller, my OpenAPI(Swagger) endpoint started to complain with the following error message:

Conflicting method/path combination "POST api/Orders" for actions - eShopExample.Web.Controllers.OrdersController.CreateOrder (eShopExample),eShopExample.Web.Controllers.OrdersController.ProcessOrders (eShopExample). Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround

I find the error message itself not very insightful but taking a look at my OrdersController made it all clear:

The problem was that I had 2 methods that were both using attribute based routing(through the [HttpPost] attribute) but where resolved to the same URI; “api/orders”. To fix it I had to use an overload of the [HttpPost] attribute and specify an alternative URI: