无法加载文件或程序集“Newtonsoft.Json”或它的某个依赖项?

问题描述:

当我正在调试时,我遇到了一个例外。无法加载文件或程序集“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从不同的位置引用,而不是默认的“包”位置?如果是,请帮助我做错的地方。

任何人都可以帮助我。

+0

我不明白,您是否说它现在可以工作,但您想知道它为什么没有? –

+0

@ user3739842,我编辑了我的问题。对不起,不清楚。我想知道为什么当我开始从不同位置引用dll而不是默认的“包”位置时,我得到异常。 – Siva

我会努力改变绑定重定向到 < bindingRedirect oldVersion =“0.0.0.0-9.0.1.0” NEWVERSION =“9.0.1.0”/>

如果这没有帮助尝试通过这个工具来检查您运行可执行文件的新位置,以便查看实际丢失的内容: https://*.com/a/44251000/2819746