2
votes

I am upgrading NHibernate, Castle.Core, Castle.Windsor (from 2.5 to 3.3)

IIS Version: 7.5

I have this in my web.config

<configuration>
<system.web>
    <httpModules>
          <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
    </httpModules>
</system.web>
<system.webServer>
     <modules runAllManagedModulesForAllRequests="true">
          <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor"/> 
    </modules>
</system.webServer>
</configuration>

When I run my web application I straight away get runtime error page without any exceptions..and after checking the event logs I found this,

Exception information: Exception type: ConfigurationErrorsException Exception message: Could not load type 'Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule' from assembly 'Castle.Windsor'. at System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) at System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, Boolean checkAptcaBit) at System.Web.Configuration.Common.ModulesEntry.SecureGetType(String typeName, String propertyName, ConfigurationElement configElement)
at System.Web.Configuration.Common.ModulesEntry..ctor(String name, String typeName, String propertyName, ConfigurationElement configElement) at System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) at System.Web.HttpApplication.GetModuleCollection(IntPtr appContext)
at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) Could not load type 'Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule' from assembly 'Castle.Windsor'. at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) at System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) at System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase)

Not able to find any solution for this....

1
What version of IIS are you running on and is the <modules> section inside of configuration/system.webServer?Russ Cam
If you are using the .NET 4.0 rather than 4.5 DLLs make sure you've got the full framework DLL rather than the client profile one, as the PerWebRequestLifestyleModule class is compiled out of the client profile one.Jonathon Rossi
@RussCam: updated the description.Jigar Sheth
@JonathonRossi: Yes I am using .NET4.0 and it is full framework build and not a client profile one.Jigar Sheth
@JigarSheth You won't need to register it in <httpModules> in IIS 7.5, only in <modules>.Russ Cam

1 Answers

5
votes

Firstly, there is no need to declare <httpModules> in IIS 7.5, and defining the <modules> tag within the <system.webServer> is enough. Secondly, "Could not load type ..." is related to incorrect type, dll or even namespace. I think the required "PerWebRequestLifestyleModule" class has been moved to a new assembly, so you just need to update your nuget packages in order to add Castle.Facilities.AspNet.SystemWeb and replace the code below.

<modules runAllManagedModulesForAllRequests="true">
    <add name="PerRequestLifestyle" type="Castle.Facilities.AspNet.SystemWeb.PerWebRequestLifestyleModule, Castle.Facilities.AspNet.SystemWeb" />
</modules>