You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用NUnit3控制台运行测试时遇System.Runtime 4.2.0.0未找到异常求助

Fixing System.Runtime 4.2.0.0 Not Found Error with NUnit Console Runner and .NET Core 2.0

Hey there, I’ve run into similar headaches working with NUnit and .NET Core projects, so let’s break down what’s going on and how to fix it:

Why This Happens

The core issue here is a compatibility mismatch between the NUnit Console Runner version you’re using (3.8.0) and your .NET Core 2.0 test project. The traditional nunit3-console.exe is built for .NET Framework, and while it supports .NET Core, older versions have limited compatibility with newer .NET Core runtime assemblies like System.Runtime 4.2.0.0. Your .NET Framework 4.5 test works fine because the console runner is natively designed for that environment.

Step-by-Step Solutions

1. Upgrade the NUnit Console Runner to Match Your Framework Version

You mentioned installing NUnit framework 3.10.1, but you’re still using the outdated 3.8.0 console runner. Make sure they’re in sync:

  • Uninstall the old console runner package:
    Uninstall-Package nunit.consolerunner -Version 3.8.0
    
  • Install the compatible version (3.10.1 or newer):
    Install-Package nunit.consolerunner -Version 3.10.1
    
    Then retry running your tests with the updated runner.

For .NET Core projects, the most reliable way to run tests is using the dotnet test command—it automatically handles .NET Core runtime dependencies without manual configuration. Here’s how:

  1. Navigate to your test project directory in the console:
    cd D:\Code_Trials\BoMLibrary\BomTest
    
  2. Run the tests:
    dotnet test
    
    Ensure your test project has these essential NuGet packages installed (add them if missing):
    • Microsoft.NET.Test.Sdk
    • NUnit3TestAdapter

3. Verify Your Test Project’s .csproj Configuration

Double-check your .csproj file to confirm it’s properly set up for .NET Core 2.0 and includes all required packages. Here’s a minimal working example:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="NUnit" Version="3.10.1" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
  </ItemGroup>
</Project>

4. Skip Manual System.Runtime Installs

You don’t need to install System.Runtime manually via NuGet for .NET Core projects—it’s included as part of the .NET Core runtime. Manually adding specific versions will only cause conflicts, so remove any System.Runtime packages you installed earlier.

Additional Checks

If you’re still stuck, confirm your machine has the .NET Core 2.0 SDK/runtime installed. You can verify this with:

dotnet --list-runtimes

Missing runtime components often lead to assembly loading errors like the one you’re seeing.

内容的提问来源于stack exchange,提问作者Rahul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:15:46