Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0

I recently installed CsvHelper (https://joshclose.github.io/CsvHelper/) when i try to use the library I get the following error:

Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

In my app.config I have 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>

Also in my project I have reference to

\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll

Its version is 4.2.0.1 I am not sure why its still trying to load 4.2.0.0 of the library.

my project is running .net 4.7.2

like image 370
Ismail Avatar asked Feb 12 '20 17:02

Ismail


1 Answers

I had the same problem today in a multi project solution, System.Threading.Tasks.Extensions got installed by embedding the Autofac package. After removing and reinstalling Autofac (via nuget) in both projects, the two packages.config contained the same entry

<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />

but while one project referenced the correct dll in

packages\System.Threading.Tasks.Extensions.4.5.4\lib

the other one referenced the older version in

packages\System.Threading.Tasks.Extensions.4.5.2\lib

After manually removing the older dll from the references (not via nuget) and embedding the correct one, everything worked again. I don't see why the correct packages.config entry did not enforce the correct reference.

EDIT:

If it works on your dev machine but not on the machine you deployed to, don't forget to deploy the binding redirects in web.config / app.config. In my case they look like so:

<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>
like image 70
IngoB Avatar answered Sep 20 '22 15:09

IngoB