Castle Windsor从2.5升级到3.3(ASP.Net MVC)

时间:2014-09-17 07:12:48

标签: c# asp.net-mvc castle-windsor

我正在升级NHibernate,Castle.Core,Castle.Windsor(从2.5到3.3)

IIS版本:7.5

我在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>

当我运行我的Web应用程序时,我立刻得到运行时错误页面,没有任何例外......在检查事件日志后我发现了这个,

  

异常信息:       异常类型:ConfigurationErrorsException       异常消息:无法加载类型'Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule'   装配'Castle.Windsor'。在   System.Web.Configuration.ConfigUtil.GetType(String typeName,String   propertyName,ConfigurationElement configElement,XmlNode节点,   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(字符串   typeName,String propertyName,ConfigurationElement configElement)
  在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)
  在System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr   appContext,HttpContext上下文,MethodInfo []处理程序)at   System.Web.HttpApplication.InitSpecial(HttpApplicationState状态,   MethodInfo [] handlers,IntPtr appContext,HttpContext context)at   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr的   appContext,HttpContext context)at   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr的   appContext)无法加载类型   'Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule'来自   装配'Castle.Windsor'。在   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   System.RuntimeType.GetType(String。的loadTypeFromPartialName)   typeName,Boolean throwOnError,Boolean ignoreCase,Boolean   reflectionOnly,StackCrawlMark&amp; stackMark)at   System.Type.GetType(String typeName,Boolean throwOnError,Boolean   在System.Web.Compilation.BuildManager.GetType(String。的ignoreCase)   typeName,Boolean throwOnError,Boolean ignoreCase)at   System.Web.Configuration.ConfigUtil.GetType(String typeName,String   propertyName,ConfigurationElement configElement,XmlNode节点,   Boolean checkAptcaBit,Boolean ignoreCase)

无法为此找到任何解决方案....

1 个答案:

答案 0 :(得分:1)

首先,无需在IIS 7.5中声明<httpModules>,而在<modules>中定义<system.webServer>标记就足够了。 其次,“无法加载类型...”与错误的类型,dll甚至命名空间有关。我认为所需的“ PerWebRequestLifestyleModule”类已移至新程序集,因此您只需更新nuget包即可添加Castle.Facilities.AspNet.SystemWeb并替换下面的代码。

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