2

I working on "Code Camper" sample SPA application. I am running the app on VS 2010 with MVC 4 installed. But I ran into problem with LookupsController.

Here is the error I got:

    "exceptionMessage":"Multiple actions were found that match the request: \r\nSystem.Collections.Generic.IEnumerable`1[CodeCamper.Model.Room] GetRooms() on type
 CodeCamper.Controllers.LookupsController\r\nSystem.Collections.Generic.IEnumerable`1[CodeC
amper.Model.TimeSlot] GetTimeSlots() on type 
CodeCamper.Controllers.LookupsController","exceptionType":"System.InvalidOperationException
","stackTrace":"   at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectActio
n(HttpControllerContext controllerContext)\r\n   at 
System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext 
controllerContext)\r\n   at 
System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, 
CancellationToken cancellationToken)\r\n   at 
System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage 
request, CancellationToken cancellationToken)\r\n   at 
System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, 
CancellationToken cancellationToken)"
4
  • Well, do you have multiple methods with the same (action) name? Commented Dec 31, 2012 at 17:01
  • No I just have my controller like this (github.com/obkalu/SPA-CodeCamper/blob/master/CodeCamper/…) Commented Dec 31, 2012 at 17:04
  • Is you route config idential to this? github.com/obkalu/SPA-CodeCamper/blob/master/CodeCamper/… It looks like your request is somehow matching the non action route and finding two methods with the prefix GET and erroring. Have you kept the route constraint in for ID? 'constraints: new { id = @"^\d+$" } // id must be all digits' Commented Jan 2, 2013 at 11:17
  • @MarkJones, yes the route config is same as the source code... Commented Jan 2, 2013 at 18:47

1 Answer 1

3

I found the answer!

When you create a web api project, by default there is this line of code in global.asax.cs

WebApiConfig.Register(GlobalConfiguration.Configuration);

I removed it (as I saw from source code of codecamper) and now there is no problem any more! but I dont know why exatly

Sign up to request clarification or add additional context in comments.

3 Comments

WebApiConfig.Register (in App_Start) would have registered the routes again, more to the point it would have registered the standard route config which left unaltered (from the template default) looks for {controller} but not action and therefore uses the method naming convention. If that route Won the race it would have have multiple actions beginning with the word Get and given you your error.
tnx @MarkJones for your description.
@MarkJones This worked for me too... so u're saying the routes config maps the route to a controller method, and WebApiConfig does the same thing, and if the 2 conflict, you get an error?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.