Moq 4.13.1 incompatibility with Task.Extensions


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=, 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?

asked on Stack Overflow Feb 13, 2020 by Nesan Mano • edited Feb 13, 2020 by Nkosi

1 Answer


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"?>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="" newVersion="" />
answered on Stack Overflow Jun 3, 2020 by kalitsov

User contributions licensed under CC BY-SA 3.0