10

有时在构建并启动我的 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
4

2 回答 2

6

根据 Roman Nikitin 评论:

我自己发现了问题。引用错误System.Web.Optimization.dll,我的网站尝试使用旧版本。删除包然后重新添加并非每次都有帮助。

解决方案是:从所有网站中完全删除旧包、引用和包配置,然后重新添加。

于 2014-03-10T13:58:21.040 回答
0

当尝试访问基于 .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 应用程序(在高级设置下)
于 2021-11-26T14:48:44.120 回答