【问题标题】:.Net ajax post method Newtonsoft.Json assembly.Net ajax post 方法 Newtonsoft.Json 程序集
【发布时间】: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


【解决方案1】:

首先,您能否发布您在尝试升级 Newtownsoft.Json 软件包时收到的错误消息。听起来您可能会在有依赖项时尝试将其删除。

其次,如果您收到指示需要 v11 的错误消息,则几乎可以肯定是因为一个或多个引用的组件需要该版本。 将解决方案中所有引用的程序集升级到 v11+ 是一种选择。 您可能还需要考虑在程序集绑定中引用 v11。

也许试试这样的东西:-

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
  </dependentAssembly>

让我们知道您的进展情况。

【讨论】:

    猜你喜欢
    • 2013-07-20
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 2019-05-09
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 2012-09-04
    相关资源
    最近更新 更多