asp.net-web-apiswaggerasp.net-web-api-routingswashbuckleattributerouting

Only one GET method in controller and yet getting "Not supported by Swagger 2.0: Multiple operations with path"


I know there are many questions with the same title but this one is different.

I was getting this error on my product controller, so to investigate the problem I created a demo controller in the ASP.NET Web API 2. DemoController.cs

namespace WMWebAPIControllers.Controllers
{
[RoutePrefix("api/Demo")]
public class DemoController : ControllerBase
{
    [HttpGet]
    [Route("")]
    public async Task<IHttpActionResult> GetProducts(int CatalogType, string ProductNo)
    {
        return Ok();
    }
}}

The strange thing is demo controller have only one method. There is no method with which swagger would find ambuigity.

I don't understand the problem. Below is the swagger error.

500 : {"message":"An error has occurred.","exceptionMessage":"Not supported by Swagger 2.0: Multiple operations with path 'api/Demo' and method 'GET'. See the config setting - \"ResolveConflictingActions\" for a potential workaround","exceptionType":"System.NotSupportedException"


Solution

  • The problem was I had one public method without route attribute. So swagger found ambiguity with the GetProducts() method which was configured for the empty route.

    Marked that public method as [NonAction] attribute and issue solved.

    It can also be marked private/protected to solve this problem but in my case, it was an interface method.

    Hope this will help someone.