【问题标题】:MVC Applications break after Windows update of Oct 1510 月 15 日 Windows 更新后 MVC 应用程序中断
【发布时间】:2014-10-16 07:56:30
【问题描述】:

今天早上我醒来发现我的服务器上的 MVC 4 Web 应用程序坏了。

错误信息是:

An exception of type 'System.IO.FileNotFoundException' occurred in 
mscorlib.dll but was not handled in user code.
Additional information: Could not load file or assembly 
'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, 
PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. 
The system cannot find the file specified.

我打开了我的 VS 项目并从代码运行它(所以在另一台计算机上),发生了同样的错误!

我检查了我的服务器日志,发现更新是在凌晨 5:06 自动安装的。其中一项更新是由安装程序包 AspNetMVC4.msi 完成的。一分钟后,我的网络应用程序上的第一个错误开始流入。

在我的开发笔记本电脑上,昨天(10 月 15 日)下午 1:10:10 运行了相同的安装程序。

两台电脑都出现同样的问题。

我从未听说过 Newtonsoft.Json(但现在我知道它是什么了)。看起来好像 MVC dll 之一(不太可能)或包 dll 之一(更有可能)引用了 Newtonsoft。

我试图从 nuget 安装 Newtonsoft。这确实有一些影响,错误从 FileNotFound 变成了 FileLoadException:

An exception of type 'System.IO.FileLoadException' occurred in 
mscorlib.dll but was not handled in user code Additional
information: Could not load file or assembly 'Newtonsoft.Json,   
Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' 
or one of its dependencies. The located assembly's manifest 
definition does not match the assembly reference. (Exception 
from HRESULT: 0x80131040)

我还尝试从 .NET 4.5 升级到 4.5.1。这没有帮助。

顺便说一句,错误发生在 Global.asax.cs 的 RegisterRoutes 中:

routes.MapHttpRoute( 
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

有什么想法吗?

【问题讨论】:

标签: c# asp.net-mvc asp.net-mvc-4 json.net


【解决方案1】:

感谢大家的好主意! 我曾尝试进行程序集重定向,但没有成功。

我最终以一种非常简单的方式解决了这个问题。我突然意识到我从来没有使用过以下路线:

routes.MapHttpRoute( 
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

所以我删除了这些行,然后又恢复了!

一些研究表明 MapHttpRoute 是旧版本 System.Web.Mvc.dll 的一部分,但不是新版本的一部分。所以新的dll与旧版本不兼容。

当我因 Windows 更新而睡觉时,正在运行的生产 Web 应用程序中断仍然困扰着我。关闭 Windows 更新可能是一种解决方案,但会使服务器更容易受到攻击......这里有什么智慧。

再次感谢大家。

【讨论】:

  • MapHttpRoute 扩展实际上是 WebAPI 的一部分,而不是 MVC。如果您没有引用更新的 WebAPI 程序集但有此代码,则会导致您出现此问题
【解决方案2】:

您需要安装Newtonsoft.Json 5.0.1 nupkg。顺便说一句,您在项目中使用的System.Web.Http.dll 的文件版本是什么?

【讨论】:

  • 我关于这个问题的评论被删除了,不知道为什么。对您和我们来说,了解发生这种情况的原因很重要。我们怀疑您的应用程序在 MVC 4 的预发布版本(可能是 4.0.20505.0)上运行,这是有风险的,如果是这种情况,您应该升级到 MVC 4 的受支持发布版本。
  • 有关修复 MVC 安全补丁问题的详细信息,请参阅此帖子:blogs.msdn.com/b/webdev/archive/2014/10/16/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-14
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
相关资源
最近更新 更多