首页 > 解决方案 > 是否有可能解决这种装配不匹配的情况?或者这是无法解决的?

问题描述

在我的程序集中我想使用

SomeLibrary.dll->Newtonsoft.Json, Version 10.0.0.0

SomeLibrary.dll通过路径引用的地方。然后我也有

Microsoft.NET.Sdk.Functions->Newtonsoft.Json, Version 9.0.0.1

Nuget 都引用了这些内容。当我这样做时,这会导致版本不匹配

JsonConvert.DeserializeObject<SomeTypeFromSomeLibrary>(json)

我能做些什么吗?:(

标签: c#.netnuget.net-assemblyversioning

解决方案


这种问题通常通过绑定重定向来解决。

对于 JSON.NET,它可能看起来像这样:

<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-10.0.0.0" newVersion="10.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

推荐阅读