gpt4 book ai didi

c# - NewtonSoft.Json 程序集不匹配

转载 作者:太空狗 更新时间:2023-10-30 01:18:43 25 4
gpt4 key购买 nike

我做了一个在类库中使用 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)

Newtonsoft.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>

这是packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FubarCoder.RestSharp.Portable" version="1.6.3" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" />
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="portable-win+net45+MonoAndroid10+MonoTouch10" />
</packages>

在此先感谢您对我的帮助

编辑:我通过一个控制台应用程序启动这个类库

这是我使用的新 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.5" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

NewtonSoft.Json 信息(在 telerikJustDecompile 上):

[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")]

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>

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

关于c# - NewtonSoft.Json 程序集不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26062483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com