簡體   English   中英

Castle Windsor 從 2.5 升級到 3.3 (ASP.Net MVC)

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

我正在升級 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.Windsor”加載類型“Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule”。 在 System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode 節點, Boolean checkAptcaBit, Boolean ignoreCase) 在 System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, Boolean checkAptcaBit) 在 System.Web.Configuration.Common.ModulesEntry.SecureGetType(String typeName, String propertyName, ConfigurationElement configElement)
在 System.Web.Configuration.Common.ModulesEntry..ctor(String name, String typeName, String propertyName, ConfigurationElement configElement) 在 System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) 在 System.Web.HttpApplication.GetModuleCollection(IntPtr)應用上下文)
在 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) 在 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) 在 System.Web.HttpApplicationFactory。 GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) 無法從程序集“Castle.Windsor”加載類型“Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule”。 在 System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, BooleanreflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack 類型) 在 System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Booleanreflectionignore, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, BooleanreflectionOnly, StackCrawlMark& stackMark) at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) at System. Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) 在 System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode 節點, Boolean checkAptcaBit, Boolean ignoreCase)

無法為此找到任何解決方案......

首先,在IIS 7.5中不需要聲明<httpModules> ,在<system.webServer>定義<modules>標簽就足夠了。 其次,“無法加載類型...”與不正確的類型、dll 甚至命名空間有關。 我認為所需的“PerWebRequestLifestyleModule”類已移至新程序集,因此您只需更新 nuget 包即可添加 Castle.Facilities.AspNet.SystemWeb 並替換以下代碼。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM