我们正在使用asp .net核心和Visual Studio 2015在asp.net web api项目中工作.project.json文件看起来像这样(只列出可能有问题的条目):
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.0.3",
"Microsoft.Net.Http": "2.2.29",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"net461": {
"frameworkAssemblies": {
"System.Runtime.Serialization": "4.0.0.0"
}
}
我在调用NewtonSoft.Json程序集的JsonConvert类的SerializeObject方法时遇到了这个问题。错误如下所示:
Exception thrown: 'System.IO.FileLoadException' in mscorlib.dll
Additional information: Could not load file or assembly 'System.Runtime.Serialization.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
检查内部异常,我看到以下内容:
{"Could not load file or assembly 'System.Runtime.Serialization.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"System.Runtime.Serialization.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"}
只有在我的计算机上安装Visual Studio 2017后才开始出现此问题。
不应该自动解决Newtonsoft.Json需要的正确依赖程序集吗?
我应该如何解决此问题?