0

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"

Kishan Vaishnav
  • 2,273
  • 1
  • 17
  • 45
  • are you sure you don't have any older dlls? maybe you renamed the project, updated dll name. Do a Clean in Visual Studio, then go check the bin / obj folders then finallly delete the Windows\Framework32 & 64 temp files as well. Once everything is gone, reload Visual studio and try again – Andrei Dragotoniu May 30 '19 at 11:58
  • @AndreiDragotoniu Where can I find Windows\Framework32 & 64 temp files? – Kishan Vaishnav May 30 '19 at 12:09
  • C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files and also Framework64. you will need to update to wherever yours is – Andrei Dragotoniu May 30 '19 at 12:13
  • I created a different project with the same controller and it's working perfectly. – Kishan Vaishnav May 30 '19 at 12:24
  • @AndreiDragotoniu I deleted all the folders in Framework64. There was no ASP.NET Files folder in the Framework folder. I cleaned the Solution, deleted obj and bin folders and restarted the whole machine. But the error persist – Kishan Vaishnav May 30 '19 at 13:01
  • 2
    I could not understand the problem in this controller but I found the problem in my main controller. It had one public method and one method with [route("")]. This was causing the ambiguity. I marked the public method as [NonAction] and the Swagger error vanished. – Kishan Vaishnav May 31 '19 at 06:00

1 Answers1

2

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.

Kishan Vaishnav
  • 2,273
  • 1
  • 17
  • 45