簡體   English   中英

.Net Ajax發布方法Newtonsoft.Json程序集

[英].Net ajax post method Newtonsoft.Json assembly

我有一個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);
    }

為什么會是這個錯誤?

首先,當您嘗試升級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>

讓我們知道您的生活。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM