C# 程序集引用版本冲突—;如何解决?

C# 程序集引用版本冲突—;如何解决?,c#,nuget,restsharp,csproj,C#,Nuget,Restsharp,Csproj,所以我有一个共享的公共库,它是参考库。我使用NuGet安装RestSharp,因此它是参考版本106.3.1。现在,我已经将特定版本设置为False,从csproj文件引用中删除了版本号,并将Private设置为true <Reference Include="RestSharp"> <HintPath>..\packages\RestSharp.106.3.1\lib\net452\RestSharp.dll</HintPath> <Speci

所以我有一个共享的公共库,它是参考库。我使用NuGet安装RestSharp,因此它是参考版本106.3.1。现在,我已经将特定版本设置为False,从csproj文件引用中删除了版本号,并将Private设置为true

<Reference Include="RestSharp">
  <HintPath>..\packages\RestSharp.106.3.1\lib\net452\RestSharp.dll</HintPath>
  <SpecificVersion>False</SpecificVersion>
  <Private>True</Private>
</Reference>

..\packages\RestSharp.106.3.1\lib\net452\RestSharp.dll
假的
真的
然后从我的主.NET Framework 4.6.1 web应用程序中引用此公共库。该web应用程序反过来引用了NuGet的另一个库,该库对RestSharp 105.1.0.0具有硬版本依赖性。由于这一点,web应用程序现在也在引用RestSharp 105.1.0.0

现在,根据我对csproj程序集引用的理解,这应该是可行的。没有。当我运行它时,当公共库(引用RestSharp 106.3.1的库)中的代码执行时,我会在运行时收到此错误:

System.IO.FileLoadException:'无法加载文件或程序集'RestSharp,版本=106.3.1.0,区域性=neutral,PublicKeyToken=598062e77f915f75'或其依赖项之一。定位的程序集清单定义与程序集引用不匹配。(HRESULT的例外:0x8013100)'

总而言之,我从我的主项目中引用了两个不同的项目。这两个项目都依赖于RestSharp,但版本不同。我认为上面的csproj更改应该修复它,但它不起作用

要解决此问题,我需要更改什么?非常感谢您的帮助

更新:我按照建议尝试了绑定重定向,如下所示:

<dependentAssembly>
     <assemblyIdentity name="RestSharp" publicKeyToken="598062e77f915f75" culture="en-us" />
     <bindingRedirect oldVersion="105.1.0" newVersion="106.3.1.0" />
 </dependentAssembly>

不幸的是,这不起作用,因为RestSharp 105.1.0没有publicKeyToken,所以现在我得到一个错误,说找不到库的105.1.0版本。还有其他想法吗

更新2:尝试删除publickeytoken和区域性:

  <dependentAssembly>
    <assemblyIdentity name="RestSharp"/>
    <bindingRedirect oldVersion="105.1.0.0" newVersion="106.3.1.0" />
  </dependentAssembly>

这也不起作用,产生了:

FileLoadException:无法加载文件或程序集“RestSharp,版本=105.1.0.0,区域性=中性,PublicKeyToken=null”或其依赖项之一。定位的程序集清单定义与程序集引用不匹配。(来自HRESULT的异常:0x8013100)


我有同样的问题

关键是105.1.0的publicKeyToken为空,即使api与106.3.1.0不同。所以它们不兼容,不能使用binding重定向

我发现了一个答案,但我没有验证它,因为它在nuget下无法实现。如果你不介意的话,你可以试试

<dependentAssembly>
    <assemblyIdentity name="RestSharp" publicKeyToken="null" culture="neutral" />
    <codeBase version="105.1.0.0" href="RestSharp.105.1.0/RestSharp.dll" />
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="RestSharp" publicKeyToken="598062e77f915f75" culture="neutral" />
    <codeBase version="106.3.1.0" href="RestSharp.106.3.1/RestSharp.dll" />
</dependentAssembly>


在你的app.config/web.config中怎么样?@UweKeim谢谢你的提示-我该怎么做?@UweKeim刚刚尝试了这个(见上面的更新)但不幸的是,这似乎不起作用,因为105.1.0版本的RESTSharp没有publicKeyToken,只需省略
publicKeyToken
,而
文化
@UweKeim尝试了这一点(见上文),但不幸的是,这并没有起到提示作用。不幸的是,这似乎不起作用。