【发布时间】:2017-01-30 21:54:01
【问题描述】:
我正在为我的 MVC-4 应用程序设置 API,当我在 Globals.asax.cs 中取消注释此行时:
WebApiConfig.Register(GlobalConfiguration.Configuration);
我在开始备份项目时收到此异常:
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)
我该怎么办?
更新 1(截图)
据我所知,JSON.Net 看起来安装正确。
更新 2
当在 Globals.Asax 中注释掉 API 路由时,JSON.Net 实际上似乎可以工作。这不会引发任何错误:
public ActionResult Index()
{
var foo = Newtonsoft.Json.JsonSerializer.Create();
return View();
}
Visual Studio 仅在取消注释此行时才会抱怨:
WebApiConfig.Register(GlobalConfiguration.Configuration);
【问题讨论】:
-
不能解决您的问题,但请考虑更新到 Web API 2.12。
-
不用担心这个问题,从nuget包管理器安装JSON.NET包就可以了。
标签: c# asp.net-mvc asp.net-mvc-4 asp.net-web-api