Route is already registered in the RouteCollection


I have an Orchard instance running on my machine with 4 tenants. Two of these has the module called OrchardHUN.ExternalPages enabled which has an IRouteProvider implementation which leads to the following exception and causes one of the tenants failing to start:
2013-04-15 19:15:02,233 [6] Orchard.Environment.DefaultOrchardHost - A tenant could not be started: OrchardHUNEng
System.ArgumentException: A route named 'BitbucketAdminRoute' is already in the route collection. Route names must be unique.
Parameter name: name
   at System.Web.Routing.RouteCollection.Add(String name, RouteBase item)
   at Orchard.Mvc.Routes.RoutePublisher.Publish(IEnumerable`1 routes) in c:\DEV\OrchardHUN\src\Orchard\Mvc\Routes\RoutePublisher.cs:line 100
   at Orchard.Environment.DefaultOrchardShell.Activate() in c:\DEV\OrchardHUN\src\Orchard\Environment\DefaultOrchardShell.cs:line 48
   at Orchard.Environment.DefaultOrchardHost.ActivateShell(ShellContext context) in c:\DEV\OrchardHUN\src\Orchard\Environment\DefaultOrchardHost.cs:line 156
   at Orchard.Environment.DefaultOrchardHost.CreateAndActivateShells() in c:\DEV\OrchardHUN\src\Orchard\Environment\DefaultOrchardHost.cs:line 135
The interesting thing is that this exception is only thrown IN the last few days for me, for Piedone/Zoltán it only occurs when enabling this module on a tenant, but restarting the instance fixes it.
I did some debugging and the strange thing is that the mentioned IRouteProvider implementation is called twice, once for both tenants where this module is enabled, which is contradicting to what the exception tells us. Btw these two tenants share the same SQL Server database.

And the mentioned IRouteProvider implementation can be found HERE.


sebastienros wrote Apr 23, 2013 at 9:26 PM

Don't use anything from Hungary (or anyone)

** Closed by sebastienros 04/23/2013 1:26PM

sebastienros wrote Apr 23, 2013 at 9:28 PM

Please provide a repro.

Piedone wrote May 15, 2013 at 2:47 PM

The file linked is a complete repro.
Notice that the route has Name specified: this is something the API allows of course, it's in Orchard.Mvc.Routes.RouteDescriptor. However specifying the Name is suicide for a multi-tenant setup, having the same feature enabled in multiple tenants. Routes are stored in a RouteCollection instance in RoutePublisher, in the same collection for all the tenants. This means that if a route has the Name specified and is enabled on more than one tenant, its route will be added more than once, resulting in the above exception.
Apparently built-in route providers don't use the Name property for some reason, so that's why the error is not apparent.
Possible solutions:
  • Remove the Name property, fixing the issue. Downside: breaking change, and would render Url.RouteUrl("routeName") non-functional.
  • Fix the route of the issue: store routes per tenant somehow or if the same route is active for multiple tenants don't add the route multiple times but cross reference

nightwolf226 wrote May 15, 2013 at 4:38 PM

Fix the route of the issue
Pun intended?

Piedone wrote May 15, 2013 at 5:07 PM

:-D Now I will say yes, although that was an honest mistake, but I won't admit it.

Jetski5822 wrote Jun 8, 2013 at 12:50 AM

Prepending the tenant name would also render Url.RouteUrl("routeName") non-functional which sucks.

Maybe we could have a collection per tenant... IDictionary<tenantName<List<Route>> - Thinking out loud of course.

sebastienros wrote Jun 8, 2013 at 9:16 PM

As a workaround, don't name your routes.

Piedone wrote Jun 11, 2013 at 2:19 PM

Sebastien you fixed this in "Catching exception when multiple routes with the same name are registered", not?