Asp.net
無法載入類型“System.Web.Optimization.StyleBundle”
有時在建構並啟動我的 MVC4 Web 應用程序後,我會收到此錯誤。它可以在重建或不重建後消失。發佈到 Windows Azure 後,我遇到了同樣的問題。
有誰知道如何解決這個錯誤?
Server Error in '/' Application. Could not load type 'System.Web.Optimization.StyleBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.TypeLoadException: Could not load type 'System.Web.Optimization.StyleBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [TypeLoadException: Could not load type 'System.Web.Optimization.StyleBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.] Inventarium.Web.Mobile.App.BundleConfig.RegisterBundles(BundleCollection bundles) in c:\dev\Inventarium\Inventarium.Web\Inventarium.Web.Mobile.App\App_Start\BundleConfig.cs:30 Inventarium.Web.Mobile.App.MvcApplication.Application_Start() in c:\dev\Inventarium\Inventarium.Web\Inventarium.Web.Mobile.App\Global.asax.cs:18 [HttpException (0x80004005): Could not load type 'System.Web.Optimization.StyleBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +4058245 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +352 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375 [HttpException (0x80004005): Could not load type 'System.Web.Optimization.StyleBundle' from assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11703488 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4870277
根據 Roman Nikitin 評論:
我自己發現了問題。引用錯誤
System.Web.Optimization.dll,我的網站嘗試使用舊版本。刪除包然後重新添加並非每次都有幫助。**解決方案是:**從所有網站中完全刪除舊包、引用和包配置,然後重新添加。
當嘗試訪問基於 .net 5 的新應用程序作為現有 .net 4.7.x 網站的子應用程序時,我們在帶有 IIS 10.10 的 Windows 2019 Server 上遇到了同樣的問題。
在我們的 Web 伺服器上,我們使用不同的 .net 框架執行多個 Web 應用程序
我們可以通過應用以下步驟來解決異常:
在伺服器上下載並安裝 .NET Core Hosting Bundle
轉到 IIS
選擇“應用程序池”
添加具有以下參數的新應用程序池:
- .NET CLR 版本:無託管程式碼
- 託管管道:經典
將此新應用程序池分配給您的新 .net 5 Web 應用程序(在高級設置下)