DLL hell - Could not load file or assembly System.Threading.Tasks.Extensions

Viewed 8103

I have very simple .NET Framework 4.7.2 app with the following nugets:

<packages>
  <package id="Autofac" version="5.1.2" targetFramework="net472" />
  <package id="DynamicData" version="6.14.8" targetFramework="net472" />
  <package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.0" targetFramework="net472" />
  <package id="MSBuildTasks" version="1.5.0.235" targetFramework="net472" developmentDependency="true" />
  <package id="ReactiveUI" version="11.2.3" targetFramework="net472" />
  <package id="Serilog" version="2.9.0" targetFramework="net472" />
  <package id="Serilog.Enrichers.Process" version="2.0.1" targetFramework="net472" />
  <package id="Serilog.Enrichers.Thread" version="3.1.0" targetFramework="net472" />
  <package id="Serilog.Sinks.File" version="4.1.0" targetFramework="net472" />
  <package id="Splat" version="9.3.11" targetFramework="net472" />
  <package id="System.Reactive" version="4.3.2" targetFramework="net472" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.7.0" targetFramework="net472" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net472" />
  <package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
</packages>

As you can see, there is System.Threading.Tasks.Extensions referenced in version 4.5.3 (I can't change this version, because other packages depend on it).

When I go to properties of this DLL reference in Visual Studio Solution Explorer, it shows version 4.2.0.1 referenced from .....\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll.

In app.config there is automatically generated binding redirect:

   <dependentAssembly>
    <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
  </dependentAssembly>

When I run the app, I get exception:

Exception message

I already tried to change binding redirect to something like:

   <bindingRedirect oldVersion="0.0.0.0-99.99.99.99" newVersion="4.5.3" />

But the issue persists. I have no idea how to resolve this dll-hell. Any help will be much appreciated.

1 Answers

When I go to properties of this DLL reference in Visual Studio Solution Explorer, it shows version 4.2.0.1 referenced from xxxxxx

First, I think you have a little misunderstanding about the DLL version and the nuget version.

version 4.5.3 is just the nuget package System.Threading.Tasks.Extensions's version number while version 4.2.0.1 is just the System.Threading.Tasks.Extensions.dll( exist in the nuget pacakge) number. They are not a concept at all. And you can see such dlls referenced in xxx.csproj file.

enter image description here

A version of the nuget package contains multiple competing DLLS for different project frameworks, which will be automatically installed into the corresponding project according to the nuget mechanism.

DLL hell - Could not load file or assembly System.Threading.Tasks.Extensions

As you said, you have a nuget package called System.Reactive version 4.3.2 that depends on System.Threading.Tasks.Extensions 4.5.3 in your project. You can see this:

enter image description here

And from your error log, it seems that the project referenced System.Threading.Tasks.Extensions.dll 4.2.0.0 which it does not exists in the nuget package System.Threading.Tasks.Extensions 4.5.3 and it should be System.Threading.Tasks.Extensions.dll 4.2.0.1. Not sure if you changed the version number or the reason for the project.

You can check these steps:

Solution

1) make sure that System.Threading.Tasks.Extensions version is 4.5.3 in packages.config file.

2) make sure that you change the dll version to 4.2.0.1 in xxx.csproj file

3) Before you reinstall these, please clean the nuget cache first, then run update-Package -reinstall under Tools-->Nuget Package Manager->Package Manager Console to reinstall the packages

4) create a new framework 4.7.2 project and then referenced these nuget packages to test whether it is caused by your project.

Related