當我正在調試時,我遇到了一個例外。無法加載文件或程序集「Newtonsoft.Json」或它的某個依賴項?
var connection = new HubConnection("http://localhost:8080/");
Exception:
Could not load file or assembly 'Newtonsoft.Json, Version=6.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)
我已經創建了一個文件夾,我甩掉了我的serverHub.exe(控制檯應用程序)和一個winforms客戶端模塊。在客戶端,當我嘗試調用上述步驟時,我得到了異常。
首先,我安裝了version = 6.0.0.0的Newtonsoft.Json,後來我將它更新到version = 9.0.1。現在我將需要的dll的(Microsoft.Asp.Net.Client.dll, Newtonsoft.Json.dll along with other dll's required)
複製到我創建的公用文件夾中。這是當我開始面對異常。
現在在我的項目中引用(Newtonsoft.Json.dll, Microsoft.Asp.Net.Client.dll)
指的是我新創建的文件夾,我從「包」位置轉儲了複製的dll。
我再次刪除這些引用並從包管理器(Microsoft.Asp.Net.Client.dll-版本:2.2.1 & Newtonsoft.Json.dll-9.0.1)下載了Nuget包。 和引用現在從package
位置引用。現在我嘗試構建我的應用程序,現在它工作正常。
的App.config(客戶的):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
的App.config(服務器):
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
如果我開始涉及到不同的位置,我會複製這些安裝的所有dll的而不是解決方案目錄下默認的「Packages」位置。我正面臨上述異常。我們不能讓dll從不同的位置引用,而不是默認的「包」位置?如果是,請幫助我做錯的地方。
任何人都可以幫助我。
我不明白,您是否說它現在可以工作,但您想知道它爲什麼沒有? –
@ user3739842,我編輯了我的問題。對不起,不清楚。我想知道爲什麼當我開始從不同位置引用dll而不是默認的「包」位置時,我得到異常。 – Siva