C# NewtonSoft.Json程序集不匹配

C# NewtonSoft.Json程序集不匹配,c#,json,json.net,.net-assembly,C#,Json,Json.net,.net Assembly,我制作了一个简单的项目,在类库中使用Json和ReshSharp Portable 当我使用应用程序时,我总是会遇到以下例外情况: 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 definit

我制作了一个简单的项目,在类库中使用Json和ReshSharp Portable

当我使用应用程序时,我总是会遇到以下例外情况:

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)
Json在库(nuget)中,没有依赖性(nuget说)。 对于这些版本,一切正常,例外情况是6.0.0.0,参考文件夹中的就是该版本

这是app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.2.28.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
NewtonSoft.Json属性(在VS中):

运行时版本:v4.0.30319 版本:6.0.0.0


在NuGet软件包中,Json.Net被引用为版本6.0.5

这类错误的常见原因是依赖程序集试图在您没有的版本中查找程序集。假设您使用了
ProjectX
ProjectX
所需的Json.NET 6,而您只有版本6.0.5。那会引起一个问题。您可以安装所需版本,也可以使用
assemblyBinding

assemblyBinding
允许您提供与请求的版本不同的版本。请求的版本为
oldVersion
,提供的版本为
newVersion

试试这个:

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.5" />
  </dependentAssembly>


如果上面代码段中的数字不匹配,请尝试调整它们,直到匹配为止。

很好解决了我的问题:-) 说明: 首先查找安装了哪个版本的Newtonsoft.Json(签入package.config文件),旧版本应该是0.0.0.0-6.0.0.0和newVersion=“您安装的”



很好的尝试,但没有成功,在同一个地方出现了相同的异常。谢谢,但是我有同样的例外(他们说的是6.0.0),你能确认一下你安装的版本吗?旧版本肯定是6.0.0.0。现在,我们需要确切地知道您安装的版本,以便将其放入新版本。我尝试过,但没有效果。您的应用程序是便携式应用程序还是常规应用程序?此外,您是否看到从
packages\Newtonsoft.Json.6.0.5\lib\portable win+net45+MonoAndroid10+MonoTouch10
位置引用的dll?它是否存在于包中?@Mrchief:异常在PCL中,但由控制台appOk启动。位置如何?@Mrchief我不明白你的问题…一次编译,dll与.pdb在同一个目录中,依此类推
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.2.28.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.5" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
[assembly: AssemblyCompany("Newtonsoft")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCopyright("Copyright © James Newton-King 2008")]
[assembly: AssemblyDescription("Json.NET is a popular high-performance JSON framework for .NET")]
[assembly: AssemblyFileVersion("6.0.5.17707")]
[assembly: AssemblyProduct("Json.NET")]
[assembly: AssemblyTitle("Json.NET Portable")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyVersion("6.0.0.0")]
[assembly: CLSCompliant(true)]
[assembly: CompilationRelaxations(8)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("Newtonsoft.Json.Dynamic, PublicKey=0024000004800000940000000602000000240000525341310004000001000100cbd8d53b9d7de30f1f1278f636ec462cf9c254991291e66ebb157a885638a517887633b898ccbcf0d5c5ff7be85a6abe9e765d0ac7cd33c68dac67e7e64530e8222101109f154ab14a941c490ac155cd1d4fcba0fabb49016b4ef28593b015cab5937da31172f03f67d09edda404b88a60023f062ae71d0b2e4438b74cc11dc9")]
[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f561df277c6c0b497d629032b410cdcf286e537c054724f7ffa0164345f62b3e642029d7a80cc351918955328c4adc8a048823ef90b0cf38ea7db0d729caf2b633c3babe08b0310198c1081995c19029bc675193744eab9d7345b8a67258ec17d112cebdbbb2a281487dceeafb9d83aa930f32103fbe1d2911425bc5744002c7")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows=true)]
[assembly: TargetFramework(".NETPortable,Version=v4.5,Profile=Profile259", FrameworkDisplayName=".NET Portable Subset")]
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.5" />
  </dependentAssembly>
<dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.4" />
      </dependentAssembly>