Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting NullReferenceException in IIS7 integrated mode

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?

like image 385
Christian13467 Avatar asked Jun 04 '26 05:06

Christian13467


1 Answers

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
like image 98
Christian13467 Avatar answered Jun 06 '26 22:06

Christian13467



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!