Skip to content

Unit tests using Moq fail with runtime error after updating Moq to 4.20.72 (failure to load System.Threading.Tasks.Extensions) #1648

Description

@fotoware-flw

Describe the Bug

Unit tests using Moq fail with runtime error after updating Moq to latest version. See details below.

Steps to Reproduce

  1. Update Moq ro 4.20.72 in a .NET Framework based unit test project
  2. Run unit tests

Expected Behavior

The unit tests run.

Exception with Stack Trace

Unit tests fail with error

Initialization method [...] threw exception. System.IO.FileLoadException: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.1, 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).
   at Moq.Async.AwaitableFactory..cctor()

Version Info

  • Moq 4.20.72
  • System.Threading.Tasks.Extensions 4.6.3
  • .Net Framework 4.8.0
  • Visual Studio 2026

Additional Info

  • It worked with an earlier version of Moq.
  • "Auto-generate binding redirects" is enabled in the unit test project.

Adding binding redirects to app.config, such as

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

or

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

changes nothing.

This seems to be a recurring issue that is repeatedly being blamed on Microsoft and users of Moq, when the common denominator is always Moq. Also, in an earlier report of this issue, it was stated by the developer that Moq deliberately uses an old version of System.Threading.Tasks.Extensions to avoid binding redirect issues, which is clearly not the case.

Back this issue
Back this issue

Activity

  1. GillesTourreau commented on Dec 10, 2025

    @GillesTourreau

    @fotoware-flw Do you have a sample repo to reproduce the error ?

  2. paladin-johng commented on Jan 22, 2026

    @paladin-johng

    @fotoware-flw Our team just ran into this issue yesterday and managed to solve it, partly by coming across your post.

    We ended up using binding redirects just as you posted, but the assembly version for System.Threading.Tasks.Extensions 4.6.3 is actually 4.2.1.0, not 4.2.0.1. So our redirect looks like this:

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

    The other thing we had to do was make sure this redirect was included in every test project that used Moq. That seemed to do the trick!

  3. added 6 commits that reference this issue on Jun 24, 2026
  4. locked and limited conversation to collaborators on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions