Search code examples
c#asp.netcastle-windsor

Windsor PerWebRequestLifestyleModule - registered, but still getting error message


I receive the following:

A first chance exception of type 'Castle.MicroKernel.ComponentResolutionException' occurred in Castle.Windsor.dll

Additional information: Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule

To fix this add

<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />

to the <httpModules> section on your web.config.

Windsor also detected you're running IIS in Integrated Pipeline mode. This means that you also need to add the module to the <modules> section under <system.webServer>.

Alternatively make sure you have Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 assembly in your GAC (it is installed by ASP.NET MVC3 or WebMatrix) and Windsor will be able to register the module automatically without having to add anything to the config file.

This has just started happening since I updated a load of NuGet references (incl Windsor, Web API, etc), and updated all the projects to .NET 4.5.1.

Whether I have the module listed and registered in <system.web> or <system.webServer> under the appropriate section, the message still appears.

Note that the Web API project in question here also references Microsoft.Web.Infrastructure, the correct version, and obviously this doesn't make a difference either.

(I didn't have to have the module listed in web.config before - but now, whether I list it in either section, both or none, referencing that helper assembly or not, I get this message).

What can I do to diagnose?


Solution

  • (Thanks to Jonathon Rossi)

    You'll also get this exception if you try to resolve something with the per-web-request lifecycle within Application_Start, because the module is registered but not initialised yet.

    The fix - don't try to resolve anything scoped in this way in Application_Start.

    (I suppose the Windsor error message is a little cryptic, assumes something else is going on ;))