Moq 4.13.1 incompatibility with Task.Extensions

1

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?

c#
.net
moq
asked on Stack Overflow Feb 13, 2020 by Nesan Mano • edited Feb 13, 2020 by Nkosi

1 Answer

2

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>
answered on Stack Overflow Jun 3, 2020 by kalitsov

User contributions licensed under CC BY-SA 3.0