PerWebRequestLifetimeManager causes application to not start

Dec 3, 2012 at 8:18 AM

Hey,

I am having a weird problem with PerWebRequestLifetimeManager.

I do this within the application bootstrapper...

builder.For<WorkContext>().Use<WorkContextImplementation>().LifetimeIs(new PerWebRequestLifetimeManager())
    .Ctor(new ResolvedParameter(typeof(IUnityContainer)));

I then kick up the application and get this...

Server Error in '/qualityinvestigator' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   System.Web.PipelineModuleStepContainer.GetEventCount(RequestNotification notification, Boolean isPostEvent) +30
   System.Web.PipelineStepManager.ResumeSteps(Exception error) +2352
   System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +128
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +686



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

It wont hit any break points, its like its failing in IIS. Have you seen this?

If I change the LifetimeManager then it works fine.

Cheers, Nick

Coordinator
Dec 3, 2012 at 3:31 PM

Hi Nick,

have you tried to remove the event hook from the PerRequestLifetimeManager?

You can find the code here

It's a wild guess though.