This project is read-only.

HttpContext.SetSessionStateBehavior can only be invoked before HttpApplication.AcquireRequestState problem

Topics: General, Troubleshooting
May 1, 2013 at 2:01 AM
Edited May 1, 2013 at 8:35 PM
I've recently upgraded a 1.4 site to 1.6. That's not the problem. I downloaded the 1.6 source two times - one for a source to compile a new Orchard site, and the other for development of modules. I made no changes to the framework/core in either. In one of the modules I was developing I installed MvcMailer. When I ran the development site I was able to send e-mails using MvcMailer with no probelm. In fact, not having any problems I went ahead and built out a lot of functionality using MvcMailer in the module (before I encountered this probelm - lesson learned).

Now I've uploaded the module to my 1.6 site. All of the functionality of my module works (pages and code) except for MvcMailer. When I hit "Submit" on my view I get an error, which shows up in the logs as:
2013-04-30 16:41:31,980 [17] Orchard.Exceptions.DefaultExceptionPolicy - An unexpected exception was caught
System.InvalidOperationException: 'HttpContext.SetSessionStateBehavior' can only be invoked before 'HttpApplication.AcquireRequestState' event is raised.
at System.Web.HttpContext.SetSessionStateBehavior(SessionStateBehavior sessionStateBehavior)
at System.Web.HttpContextWrapper.SetSessionStateBehavior(SessionStateBehavior sessionStateBehavior)
at Orchard.Mvc.Routes.ShellRoute.GetRouteData(HttpContextBase httpContext) in c:\OrchardDEVELOPMENT\src\Orchard\Mvc\Routes\ShellRoute.cs:line 54
at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext)
at Mvc.Mailer.MailerBase.CreateControllerContext()
at Mvc.Mailer.MailerBase.ViewExists(String viewName, String masterName)
at Mvc.Mailer.MailerBase.TextViewExists(String viewName, String masterName)
at Mvc.Mailer.MailerBase.PopulateBody(MailMessage mailMessage, String viewName, String masterName, Dictionary2 linkedResources)
at Mvc.Mailer.MailerBase.Populate(Action
1 action)
at Mailers.AskUsMailer.AskUs(AskUsData model)
at Controllers.AskUsController.Submitted()
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controller
I've seen some similar problems (e.g. here, but have not seen a way to resolve it.

I saw some discussion where it may be the difference between IIS and VS's server. However, I not only have this problem on the live site - I loaded up Web Matrix and ran the site I pushed to live from my local box and still had the same error.

I've compared the files in my live site with the development version and other than some unrelated things I could not turn up anything.

As is usually the case with me, it's probably something fairly simple. I'm just confused about this because for all intents and purposes the source and development code is the same (with the exception of any modules I created).

I appreciate any help/guidance. Thanks.
May 1, 2013 at 6:40 PM
Edited May 1, 2013 at 6:41 PM
Anyone have any thoughts? This is really causing me some distress because I cannot understand why it would work when I run VS but not when I push it to a live site (or use it through Web Matrix which is what I use to push to live).

I actually went and downloaded Orchard.Web today, copied over my ~/App_Data, ~/Themes and ~/Media folders, copied over my module along with EMail and Messaging modules and tried with a clean install and it gave me the same error. But still when I run it in VS it works and sends me an e-mail.

May 2, 2013 at 7:51 PM
I had to perform a straight-up "hack" to get this to work. I reverted to the 1.5 versions of ShellRoute.cs and RoutePublisher.cs (which had some references to the 1.6 ShellRoute that needed to be removed). I then built Orchard.Framework using the development source I had.

I know this is going to break something else eventually.
May 4, 2013 at 3:44 AM
Not sure I understand the issue, but should you file a bug for that maybe?
May 4, 2013 at 10:49 PM
Edited May 4, 2013 at 10:49 PM
I found a similar issue ( I posted my comments from here there and also voted on that issue. Let me know if you'd rather I post a new issue.