Mvc: Hosting Web App on Azure results in ambiguous action exception

Created on 27 Aug 2017  路  13Comments  路  Source: aspnet/Mvc

I have a simple net core 2.0 app with a razor page that serves index.html. When I launch my app from Visual Studio using IIS Express everything works perfectly, but when I publish the app to azure I get an exception thrown (see below):

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

Page: /Index
Page: /Index

Microsoft.AspNetCore.Mvc.Internal.ActionSelector.SelectBestCandidate(RouteContext context, IReadOnlyList candidates)

the call stack (before it disappears into boilerplate) is:

Microsoft.AspNetCore.Mvc.Internal.ActionSelector.SelectBestCandidate(RouteContext context, IReadOnlyList candidates)
Microsoft.AspNetCore.Mvc.Internal.MvcAttributeRouteHandler.RouteAsync(RouteContext context)
Microsoft.AspNetCore.Routing.Tree.TreeRouter+d__13.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

I can confirm that the REST endpoints of the site are working as I can get the responses I expect when calling those directly it is just the call through to the view page that is not working properly.

I have tried getting rid of all my routing config and the problem still happens.

Has anyone else experienced this same issue?

3 - Done bug

Most helpful comment

@Eilon - bug that got fixed. I'll change the Label.

All 13 comments

Try deleting your old deployment (delete files at destination when publishing).

Hi @davidfowl, thanks for getting back to me. I am already doing that, the VSTS release task has been set to delete all additional files at the destination.

I changed the logging to verbose and now have the following information to add.

2017-08-27 09:01:09.120 +00:00 [Debug] Microsoft.AspNetCore.Hosting.Internal.WebHost: Loaded hosting startup assembly TSP.Web
2017-08-27 09:01:09.121 +00:00 [Debug] Microsoft.AspNetCore.Hosting.Internal.WebHost: Loaded hosting startup assembly Microsoft.AspNetCore.Server.IISIntegration
2017-08-27 09:01:09.175 +00:00 [Debug] Microsoft.AspNetCore.Server.Kestrel: Connection id "0HL7D58K733SO" started.
2017-08-27 09:01:09.396 +00:00 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting HTTP/1.1 GET http://localhost/
2017-08-27 09:01:09.594 +00:00 [Debug] Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: The request path / does not match a supported file type
2017-08-27 09:01:10.615 +00:00 [Debug] Microsoft.AspNetCore.Routing.Tree.TreeRouter: Request successfully matched the route with name '(null)' and template ''.
2017-08-27 09:01:10.652 +00:00 [Error] Microsoft.AspNetCore.Mvc.Internal.ActionSelector: Request matched multiple actions resulting in ambiguity. Matching actions: Page: /Index
Page: /Index
2017-08-27 09:01:10.762 +00:00 [Debug] Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware: Microsoft.AspNetCore.Mvc.Internal.AmbiguousActionException occurred, checking if Entity Framework recorded this exception as resulting from a failed database operation.
2017-08-27 09:01:10.762 +00:00 [Debug] Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware: Entity Framework did not record any exceptions due to failed database operations. This means the current exception is not a failed Entity Framework database operation, or the current exception occurred from a DbContext that was not obtained from request services.
2017-08-27 09:01:10.811 +00:00 [Error] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: An unhandled exception has occurred while executing the request
Microsoft.AspNetCore.Mvc.Internal.AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

@rynowak / @pranavkm - any ideas on this?

Maybe something to do with pre-compilation and somehow it thinks there are multiple pages named /Index in the system? Maybe worth turning off pre-compilation for the purposes of debugging?

Are your views getting published in addition to precompiled views? Precompiled views would be in a assembly named {AppName}.PrecompiledViews.dll

Thank you @pranavkm and @Eilon for helping figure out what is causing the issue at least. The azure web deployment is deploying the Pages folder as well as the {AppName}.PrecompiledViews.dll. When I delete the Pages folder the issue goes away and the site works as expected. Is this a bug with MVC, or an issue with the azure webdeploy command in VSTS, or something that I am doing wrong? I haven't done anything tricky in creating the project ... at this stage it's a pretty vanilla net core 2.0 Razor Pages project.

Once again thank you for helping find a work around but I'd like to understand what the expected config / behaviour should be so I can avoid this in future.

To add to my previous comment setting the property to false in the csproj file also corrects the problem. So yes the problem is related to the precompilation as the two of you have suggested.

@pranavkm - can you take a look? This definitely sounds broken.

Yup, this one's a bug. We have two page route model providers - one for runtime compiled views and for precompiled views - and they both run independently of each other. Consequently you end up with the same route registered twice.

@Eilon - bug that got fixed. I'll change the Label.

I believe I hit this bug today. When I run the application locally everything works fine, but after publishing to Azure I started getting the ambiguous action exceptions. The pre-compiled views dll was there and the Pages directory. After deleting the Pages directory everything worked fine again.

Just encountered this myself. Publishing a single page publishes just that asset to the Pages folder, precompiled views dll isn't rebuilt/deployed. Deleting the Pages folder and restarting the app fixes it (no restart = no fix, for me anyway).

So it appears that if you use precompiled views you just have to ensure you deploy the whole app when you need to republish your views.

Hi, it looks like you are posting on a closed issue/PR/commit!

We're very likely to lose track of your bug/feedback/question unless you:

  1. Open a new issue
  2. Explain very clearly what you need help with
  3. If you think you have found a bug, include detailed repro steps so that we can investigate the problem

Thanks!

Hi pranavkm, thank you. I was keeping an eye on this but am new to GitHub and wasn't sure whether to open a new issue or not. I will do that today.

Thanks
Steve

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dougbu picture dougbu  路  54Comments

xaviergxf picture xaviergxf  路  35Comments

skyflyer picture skyflyer  路  40Comments

pranavkm picture pranavkm  路  35Comments

mdmoura picture mdmoura  路  33Comments