This project is read-only.


Exception when user code attempts to access route data


The following exception is happening if user code (in a module) tries to access route data by calling GetRouteData - a recent change in ShellRoute has added a call to HttpContext.SetSessionStateBehavior and this is failing

[InvalidOperationException: 'HttpContext.SetSessionStateBehavior' can only be invoked before 'HttpApplication.AcquireRequestState' event is raised.]
System.Web.HttpContext.SetSessionStateBehavior(SessionStateBehavior sessionStateBehavior) +5225251
Orchard.Mvc.Routes.ShellRoute.GetRouteData(HttpContextBase httpContext)


sncodeplex wrote Dec 15, 2012 at 4:34 PM

Here's an example of code that will cause the exception.

This code in a controller action:
        System.Web.HttpContextBase httpContext = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current);
        System.Web.Routing.RouteData routeData = System.Web.Routing.RouteTable.Routes.GetRouteData(httpContext);
The issue is that the exception is caused using a .NET Framework method - System.Web.Routing.RouteTable.Routes.GetRouteData() - so third party libraries are likely to fail to work with Orchard.

remesq wrote May 4, 2013 at 10:47 PM

It appears the 1.6 versions of ShellRoute.cs and RoutePublishing.cs (which has methods from ShellRoute.cs) cause any modules that use GetRouteData cause this Invalid Operation error. In my case I am using a third-party .dll that uses GetRouteData, so it's not something I could work around easily.

The only way I could get my module to work was to revert to the 1.5 versions of ShellRoute.cs and RoutePublisher.cs (i.e., I copied them over into my 1.6 Framework folder (~/src/Orchard/Mvc/Routes)). I then compiled only Orchard.Framework and took the .dll file and copied it over to Orchard.Web's ~/bin folder.

pszmyd wrote May 10, 2013 at 1:33 PM

Fixed in changeset a7a4bfa66799

sfmskywalker wrote Mar 28, 2014 at 1:28 AM

Fixed in changeset 81f0e03ab343e44dc5e4d8800ff1612e6b54a492