Windows 10更新后,MVC应用程序中断

今天早上我醒来时发现我服务器上的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完成的。 一分钟后,我的Web应用程序上的第一个错误开始流入。

在我的开发笔记本电脑上,同样的安装程序昨天(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 } ); 

有任何想法吗?

谢谢你的好主意! 我曾尝试进行程序集重定向,但它没有用。

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

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

所以我删除了这些线和presto,所有工作再次!

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

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

再次感谢大家。

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