Skip to content

Ambiguous routes reported incorrectly #45

Description

@richardp-au

I have the following controller in my project:

namespace MyProject.Api.Version1
{
    [RoutePrefix("api/something")]
    public class SomethingController : ApiController
    {
        [Route("")]
        [HttpGet]
        public IHttpActionResult GetSomething()
        {
            return Ok();
        }

        [Route("else")]
        [HttpGet]
        public IHttpActionResult GetSomethingElse()
        {
            return Ok();
        }
    }
}

When I issue a GET /api/something or GET /api/something/else, I get an InvalidOperationException (details below). The exception message is:

Multiple actions were found that match the request: 
    Something on type MyProject.Api.Version1.SomethingController
    SomethingElse on type MyProject.Api.Version1.SomethingController

Despite the issue with the routes not being detected properly, I would've thought that if there was an error with multiple routes being detected, that it would throw an AmbigiousApiReqestException (using 3.0.0-beta3). Also note that Ambiguous is incorrectly spelt in that exception name.

I've also tried moving the GetSomethingElse() method into a separate SomethingElseController but that doesn't make a difference.

System.InvalidOperationException was unhandled by user code
  HResult=-2146233079
  Message=Multiple actions were found that match the request: 
Something on type MyProject.Api.Version1.SomethingController
SomethingElse on type MyProject.Api.Version1.SomethingController
  Source=MyProject
  StackTrace:
       at MyProject.Api.GlobalExceptionHandler.Handle(ExceptionHandlerContext context) in [...]\MyProject\Api\GlobalExceptionHandler.cs:line 19
       at System.Web.Http.ExceptionHandling.ExceptionHandler.HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)
       at System.Web.Http.ExceptionHandling.ExceptionHandler.System.Web.Http.ExceptionHandling.IExceptionHandler.HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)
       at System.Web.Http.ExceptionHandling.LastChanceExceptionHandler.HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)
       at System.Web.Http.ExceptionHandling.ExceptionHandlerExtensions.<HandleAsyncCore>d__0.MoveNext()
  InnerException: 

If I look at the actual exception inside the global exception handler's ExceptionHandlerContext.Exception, the stack trace starts with:

at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)
at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)
at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
[...]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions