今天早上我醒来发现我的服务器上的 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。这确实产生了一些效果,错误从 File Not Found 变为 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 }
);
有任何想法吗?