Jigar Sheth
Jigar Sheth

Reputation: 636

Castle Windsor upgrade from 2.5 to 3.3 (ASP.Net MVC)

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....

Upvotes: 2

Views: 805

Answers (1)

Mahyar Mottaghi Zadeh
Mahyar Mottaghi Zadeh

Reputation: 1325

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>

Upvotes: 5

Related Questions