I’ve an application runing .NET 4.0 with
- MVC 3.0
- Microsoft ServiceLocator 1.0
- StructureMap 2.6.2
- StructureMap Adapter 1.1.0.2
- NHibernate 3.1.0.4000
- Log4Net 1.2.10
The application is running well in development server, IIS6 and IIS7 classic mode.
Running the same application in IIS7 integrated mode gives after Global.asax Application_Start an NullReferenceException.
The stacktrace is:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.PipelineStepManager.ResumeSteps(Exception error) +1116
System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +89
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +189
The attached debugger does not break at exception. But the page shows the yellow page of death.
Any idea where I can look or hook to fix the error?
According to Error when deploying ASP.NET MVC NHibernate app to IIS7 and a lot other posts it is not supported to initialized NHibernate in Application_Start anymore if application is running in integrated mode. I found no real reason for that behavior. May be that Darins answer is the reason, but I found no access to HttpContext.Current in NHibernate initialization code.
The workarounds are: