【发布时间】:2018-10-09 08:44:12
【问题描述】:
我有一个 Aspx Web 应用程序,其中我有一个从 Ajax 帖子调用的 WebMethod,问题是在进行调用时,它会抛出一个:
"Could not load file or assembly 'Newtonsoft.Json, Version=11.0.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)"
我已经尝试卸载并重新安装 Newtonsoft.Json 块,但它不起作用,我拥有的版本是 10.0.2,所以我现在不知道为什么要寻找 11.0 版本,这就是我的 web.config 上有:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0"/>
这是我的 ajax 调用:
$.ajax({
type: "POST",
url: "call.aspx/getToken",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
data = JSON.parse(data.d);
apiKey = data[0].apiKey;
sessionId = data[0].sessionId;
token = data[0].token;
initializeSession();
}
});
这是我的网络方法:
[System.Web.Services.WebMethod(EnableSession = true)]
public static string getToken()
{
//some code
return JsonConvert.SerializeObject(ListVar);
}
为什么会出现这个错误?
【问题讨论】:
-
你的代码后面有 using 语句吗? JsonConvert 没有给你一个错误?
-
Fwiw,我的 bin 中有 Newtonsoft.Json.dll,而我的 web.config 中没有程序集绑定。
标签: asp.net .net ajax json.net