Skip to content

NUnit 4 needs System.Threading.Tasks.Extensions for net472 tests #4581

Description

@sandrohanea

If using a net472 project, and NUnit 4, async tests are failing to run if System.Threading.Tasks.Extensions is not installed separately.

Exception:

System.IO.FileNotFoundException : 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 system cannot find the file specified.

at NUnit.Framework.Internal.AwaitAdapter.FromAwaitable(Object awaitable)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await[TResult](Func`1 invoke)
at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context)
at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
at NUnit.Framework.Internal.ContextUtils.<>c__DisplayClass1_0`1.<DoIsolated>b__0(Object _)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at NUnit.Framework.Internal.ContextUtils.DoIsolated(ContextCallback callback, Object state)
at NUnit.Framework.Internal.ContextUtils.DoIsolated[T](Func`1 func)
at NUnit.Framework.Internal.Execution.SimpleWorkItem.PerformWork()

Example csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
	  <OutputType>Library</OutputType>
	  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
	  <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
	  <PackageReference Include="NUnit" Version="4.0.1" />
	  <PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
  </ItemGroup>

</Project>

Example test:

using NUnit.Framework;
using System;
using System.Threading.Tasks;
namespace NUnitRepro
{
    public class Tests
    {
        [Test]
        public async Task NUnitAsync()
        {
            await Task.Delay(1000);
            Console.WriteLine("Hello World!");
            Assert.Pass("Success");
        }
    }
}

Workaround:
Just manually install:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions