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)