I've read these questions:
Multiple actions were found that match the request: webapi
Web API Routing - multiple actions were found that match the request Multiple actions were found that match the request Web API?
And I've updated my RouteConfig as follows:
routes.MapRoute(
name: "Receipt",
url: "api/{controller}/{action}/{id}",
defaults: new { controller = "Receipt", action = "Post", source = UrlParameter.Optional }
);
Creating this new route map hasn't helped to fix the problem in the slightest
Here's the relevant functions in the Controller:
public HttpResponseMessage Post ([FromBody]CreateReceiptViewModel source)
{
try
{
// stuff happens here
}
catch (Exception ex)
{
// something went wrong, save exception data to the database
// RecordError(ex, "Post Receipt", "ReceiptController/Post");
}
}
//public void RecordError(Exception ex, string action = "", string origin = "PocketPlooto API")
//{
// Error Error = new Error
// {
// Date = DateTime.Now,
// Detail = ex.ToString(),
// Message = ex.Message,
// Origin = origin,
// StackTrace = ex.StackTrace,
// Action = action
// };
// db.Errors.Add(Error);
// db.SaveChanges();
//}
The function is fairly large so I feel it would be impractical to include here.
Interestingly enough, while RecordError
is commented, the post happens fine.
If I uncomment it, the error occurs (my test environment doesn't allow me to see it in a format other than JSON, apologies for the inconvenience):
"Message":"An error has occurred.",
"ExceptionMessage":"Multiple actions were found that match the request: \r\nPost on type WebApiService.Controllers.ReceiptController\r\nRecordError on type WebApiService.Controllers.ReceiptController",
"ExceptionType":"System.InvalidOperationException",
"StackTrace":" at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(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.d__1.MoveNext()"
Unfortunately I don't really understand the stack trace and since there clearly isn't any duplicate actions here, I can't even begin to guess what Web Api is doing or why having this problem in the controller is a problem.
Can anyone provide any clarity on what the stack trace means and why the extra function is a problem?