nunit-console: Exception when targeting .NET Framework with .NET 7 installed

Exception System.TypeInitializationException,    Exception thrown executing tests in B:\repos\Libraries\New folder\bin\Debug\net48\New folder.dll
The type initializer for 'NUnit.Engine.Services.RuntimeFrameworkService' threw an exception.
   at NUnit.Engine.Services.RuntimeFrameworkService.ApplyImageData(TestPackage package)
   at NUnit.Engine.Services.RuntimeFrameworkService.SelectRuntimeFramework(TestPackage package)
   at NUnit.Engine.Runners.MasterTestRunner.GetEngineRunner()
   at NUnit.Engine.Runners.MasterTestRunner.Explore(TestFilter filter)
   at NUnit.VisualStudio.TestAdapter.NUnitEngine.NUnitEngineAdapter.Explore(TestFilter filter) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitEngine\NUnitEngineAdapter.cs:line 88
   at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyPath, IGrouping`2 testCases, TestFilter filter) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 275
InnerException: System.ArgumentException: Unknown framework version 7.0
Parameter name: version
   at NUnit.Engine.RuntimeFramework.GetClrVersionForFramework(Version frameworkVersion)
   at NUnit.Engine.RuntimeFramework..ctor(RuntimeType runtime, Version version, String profile)
   at NUnit.Engine.RuntimeFramework.GetNetCoreRuntimesFromDirectoryNames(IEnumerable`1 dirNames)
   at NUnit.Engine.RuntimeFramework.FindDotNetCoreFrameworks()
   at NUnit.Engine.RuntimeFramework.FindAvailableFrameworks()
   at NUnit.Engine.RuntimeFramework.get_AvailableFrameworks()
   at NUnit.Engine.Services.RuntimeFrameworkService..cctor()
No test is available in B:\repos\Libraries\New folder\bin\Debug\net48\New folder.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

Reproduce

  1. Install .NET 7 SDK
  2. Create an unit test project by using dotnet new nunit
  3. Update all dependencies to latest version
  4. Target net48

Full csproj

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

  <PropertyGroup>
    <TargetFrameworks>net48</TargetFrameworks>
    <RootNamespace>New_folder</RootNamespace>
    <ImplicitUsings>disable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <LangVersion>preview</LangVersion>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
    <PackageReference Include="NUnit" Version="3.13.2" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
    <PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
    <PackageReference Include="coverlet.collector" Version="3.1.2" />
  </ItemGroup>

</Project>

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 27 (19 by maintainers)

Commits related to this issue

Most upvoted comments

This is the console project. However, I happen to know that the adapter incorporated the fix in version 4.3.0.

This issue has been resolved in version 3.16.0

The release is available on: GitHub. NuGet packages are also available NuGet.org and Chocolatey Packages may be found at Chocolatey.org

Would you care to look into this?

@CharliePoole Yes, I wouldn’t mind. I now ran into this issues twice. Can you create a new ticket outlining what you expect (copy what you said above?) and assign it to me.

@madelson The PR to fix this issue (#1175) has been merged. Are you having a different problem than what’s fixed there? Have you tried out the latest dev release on our myget feed?

That said, I see from #4085 that you actually ran into the problem using the NUnit 3 Visual Studio adapter. The adapter bundles its own copy of the NUnit engine, which is normally the latest release version at the time the adapter is released. Consequently, nothing we fix in the engine (which is where the problem lies) will be reflected in the adapter.

@OsirisTerje any thoughts on how we should deal with this?