4

So I have a shared Common library, which is reference RestSharp. I used NuGet to install RestSharp so it is reference version 106.3.1. Now, I have set Specific Version to False, I removed the version number from the csproj file reference, and I set Private to true.

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

This common library is then referenced from my main .NET Framework 4.6.1 web application. That web application, in turn is referencing another library from NuGet, which has a hard version dependency on RestSharp 105.1.0.0. Because it depends on that, the web application is also now referencing RestSharp 105.1.0.0.

Now, based on my understanding of csproj assembly references this should work. It doesn't. When I run it, I get this error at runtime when the code in the Common library (the one that references RestSharp 106.3.1) executes:

System.IO.FileLoadException: 'Could not load file or assembly 'RestSharp, Version=106.3.1.0, Culture=neutral, PublicKeyToken=598062e77f915f75' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

To summarize, I am referencing two different projects from my main project. Both of these projects take a dependency on RestSharp, but different versions. I thought that the above csproj change should fix it but it doesn't work.

What do I need to change to fix this DLL hell issue? Any help here is greatly appreciated.

Update: I tried a binding redirect as suggested, like so:

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

This didn't work unfortunately because there is no publicKeyToken for RestSharp 105.1.0, so now I am getting an error saying that the 105.1.0 version of the library can't be found. Any other ideas?

Update 2: Tried removing publickeytoken and culture:

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

This also didn't work, producing:

FileLoadException: Could not load file or assembly 'RestSharp, Version=105.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

A X
  • 905
  • 2
  • 13
  • 31
  • 1
    How about [adding a binding redirect](https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions#redirecting-assembly-versions-at-the-app-level) in your app.config/web.config? – Uwe Keim Aug 18 '18 at 21:53
  • @UweKeim Thanks for the tip - how would I do that? – A X Aug 18 '18 at 21:54
  • @UweKeim Just tried this (see update above) but unfortunately this doesn't seem to work because there is no publicKeyToken for the 105.1.0 version of RestSharp – A X Aug 18 '18 at 22:06
  • Just leave out the `publicKeyToken` and the `culture`. – Uwe Keim Aug 18 '18 at 22:09
  • @UweKeim Tried this (see above) but unfortunately is not working – A X Aug 18 '18 at 22:12
  • Any other possibilities? – A X Aug 18 '18 at 22:13
  • Maybe [enabling Fusion logging](https://stackoverflow.com/q/255669/107625) will help you find the root cause of the error. – Uwe Keim Aug 18 '18 at 22:14

1 Answers1

2

I have the same question.

The key is that 105.1.0's publicKeyToken is null, even the api is different with 106.3.1.0. So they're not compatible and can not use bingding redirect.

There is a answer I founded but I have not validate it, because it can't under nuget. You can try if you don't mind that.

<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>
san
  • 63
  • 6