3
votes

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?

2
Are you loading HttpModules or HttpHandlers? IIS6, IIS7 Classic and Cassini use the same setting whereas IIS7 Integrated differs in the way you have to setup an HttpHandler. stackoverflow.com/questions/821934/…Andreas
Andreas, I've only a global.asax and no other modules or handler. NHibernate is initialized in Application_Start. I will try the fix given in your link.Christian13467

2 Answers

3
votes

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:

  • use a module for initialization of nhibernate
  • initialize nhibernate in Application_BeginRequest but assert that it is initialized only once
1
votes

When running in integrated mode, objects such as the HttpContext, Request, Response, Session, ... are not available in Application_Start. So make sure none of your code tries to ever access them in this method.