Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moq 4.13.1 incompatibility with Task.Extensions

Tags:

c#

.net

moq

I am trying to run a unit test that uses Moq. the problem is I keep getting the follwing with Visual studio 2019.

Message: System.TypeInitializationException : The type initializer for 'Moq.DefaultValueProvider' threw an exception. ----> System.IO.FileLoadException : 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)

I am using the latest version of Moq 4.13.1 and System.Threading.Tasks.Extensions v.4.5.3 Is there any specific version of System.Threading.Tasks.Extensions or .NET that should be used with Moq?

like image 490
Nesan Mano Avatar asked Feb 13 '20 22:02

Nesan Mano


Video Answer


1 Answers

You could add an application configuration file to you test project (App.config) and perform a binding redirect to the currently installed System.Threading.Tasks.Extensions version e.g.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <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>
    </assemblyBinding>
  </runtime>
</configuration>
like image 165
kalitsov Avatar answered Oct 01 '22 02:10

kalitsov