DotNetAnalyzers / AspNetCoreAnalyzers

MIT License
62 stars 4 forks source link

Ambiguous match routes #62

Open JohanLarsson opened 5 years ago

JohanLarsson commented 5 years ago
namespace AspBox
{
    using System.Collections.Generic;
    using Microsoft.AspNetCore.Mvc;

    [Route("api/values")]
    [Route("api/values/{id}")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            return new string[] { "value1", "value2" };
        }

        [HttpGet]
        public ActionResult<string> Get(int id)
        {
            return $"'{id}'";
        }
    }
}
AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

 AspBox.ValuesController.Get (AspBox)
 AspBox.ValuesController.Get (AspBox)
Microsoft.AspNetCore.Mvc.Internal.ActionSelector.SelectBestCandidate(RouteContext context, IReadOnlyList<ActionDescriptor> candidates)
Microsoft.AspNetCore.Mvc.Internal.MvcAttributeRouteHandler.RouteAsync(RouteContext context)
Microsoft.AspNetCore.Routing.Tree.TreeRouter.RouteAsync(RouteContext context)
Microsoft.AspNetCore.Routing.RouteCollection.RouteAsync(RouteContext context)
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)