【发布时间】: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 }
);
有什么想法吗?
【问题讨论】:
-
你用nuGet安装了哪个版本,可以试试bindingRedirect重定向到新版本见msdn.microsoft.com/en-us/library/eftw1fys(v=vs.110).aspx
-
您安装了哪个版本的 Newtonsoft.Json?
-
程序集绑定重定向也能解决这个问题吗?
标签: c# asp.net-mvc asp.net-mvc-4 json.net