Asp.net .NETAJAX post方法Newtonsoft.Json程序集
我有一个Aspx web应用程序,其中有一个WebMethod,我正在从Ajax帖子中调用它,问题是在调用时,它会抛出一个:Asp.net .NETAJAX post方法Newtonsoft.Json程序集,asp.net,.net,ajax,json.net,Asp.net,.net,Ajax,Json.net,我有一个Aspx web应用程序,其中有一个WebMethod,我正在从Ajax帖子中调用它,问题是在调用时,它会抛出一个: "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 definiti
"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 nugget,但它不起作用,我的版本是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"/>
这是我的webmethod:
[System.Web.Services.WebMethod(EnableSession = true)]
public static string getToken()
{
//some code
return JsonConvert.SerializeObject(ListVar);
}
为什么会是这个错误呢 首先,请您在尝试升级Newtownsoft.Json包时发布收到的错误消息。听起来,当您有依赖项时,您可能正在尝试删除它 其次,如果您收到一个错误,指示需要v11,那么几乎可以肯定是由于一个或多个引用组件需要该版本。 将解决方案中所有引用的程序集升级到v11+是一种选择。 您可能还想考虑在程序集绑定中引用V11。 也许可以试试这样:-
让我们了解您的进展情况。您的代码中是否有using语句?JsonConvert没有向您提供错误?Fwiw,我的bin中有Newtonsoft.Json.dll,web.config中没有程序集绑定。
[System.Web.Services.WebMethod(EnableSession = true)]
public static string getToken()
{
//some code
return JsonConvert.SerializeObject(ListVar);
}
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>