Console Runner loads wrong .NET framework version when executing tests from multiple assemblies at once
See original GitHub issueWhen running tests from multiple assemblies with different target frameworks, the console runner seems to only load the highest framework version.
For example, I have two test projects: one with target framework version 3.5 and one with target framework version 4.0. The single test case in the 3.5 project looks like this:
using System;
using NUnit.Framework;
namespace Test35
{
[TestFixture]
public class TestFor35
{
[Test]
public void Example()
{
Assert.AreEqual(new Version(2, 0, 0, 0), typeof(int).Assembly.GetName().Version);
}
}
}
The single test case in the 4.0 project looks like this:
using System;
using NUnit.Framework;
namespace Test40
{
[TestFixture]
public class TestFor40
{
[Test]
public void Example()
{
Assert.AreEqual(new Version(4, 0, 0, 0), typeof(int).Assembly.GetName().Version);
}
}
}
Now, when I run the test assemblies individually, everything is fine:
D:\temp\Nunit.Test>nunit3-console.exe --noresult Test35\bin\Debug\Test35.dll
NUnit Console Runner 3.10.0 (.NET 2.0)
Copyright (c) 2019 Charlie Poole, Rob Prouse
Freitag, 9. August 2019 00:37:25
Runtime Environment
OS Version: Microsoft Windows NT 10.0.18362.0
CLR Version: 4.0.30319.42000
Test Files
Test35\bin\Debug\Test35.dll
Run Settings
DisposeRunners: True
WorkDirectory: D:\temp\Nunit.Test
ImageRuntimeVersion: 2.0.50727
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 4
Test Run Summary
Overall result: Passed
Test Count: 1, Passed: 1, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
Start time: 2019-08-08 22:37:25Z
End time: 2019-08-08 22:37:27Z
Duration: 1.746 seconds
D:\temp\Nunit.Test>nunit3-console.exe --noresult Test40\bin\Debug\Test40.dll
NUnit Console Runner 3.10.0 (.NET 2.0)
Copyright (c) 2019 Charlie Poole, Rob Prouse
Freitag, 9. August 2019 00:37:41
Runtime Environment
OS Version: Microsoft Windows NT 10.0.18362.0
CLR Version: 4.0.30319.42000
Test Files
Test40\bin\Debug\Test40.dll
Run Settings
DisposeRunners: True
WorkDirectory: D:\temp\Nunit.Test
ImageRuntimeVersion: 4.0.30319
ImageTargetFrameworkName: .NETFramework,Version=v4.0
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 4
Test Run Summary
Overall result: Passed
Test Count: 1, Passed: 1, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
Start time: 2019-08-08 22:37:41Z
End time: 2019-08-08 22:37:42Z
Duration: 1.082 seconds
However, when I run both of them together, this happens:
D:\temp\Nunit.Test>nunit3-console.exe --noresult Test35\bin\Debug\Test35.dll Test40\bin\Debug\Test40.dll
NUnit Console Runner 3.10.0 (.NET 2.0)
Copyright (c) 2019 Charlie Poole, Rob Prouse
Freitag, 9. August 2019 00:42:16
Runtime Environment
OS Version: Microsoft Windows NT 10.0.18362.0
CLR Version: 4.0.30319.42000
Test Files
Test35\bin\Debug\Test35.dll
Test40\bin\Debug\Test40.dll
Errors, Failures and Warnings
1) Failed : Test35.TestFor35.Example
Expected: <2.0.0.0>
But was: <4.0.0.0>
bei Test35.TestFor35.Example() in D:\temp\Nunit.Test\Test35\TestFor35.cs:Zeile 12.
Run Settings
DisposeRunners: True
WorkDirectory: D:\temp\Nunit.Test
ImageRuntimeVersion: 2.0.50727
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 4
Test Run Summary
Overall result: Failed
Test Count: 2, Passed: 1, Failed: 1, Warnings: 0, Inconclusive: 0, Skipped: 0
Failed Tests - Failures: 1, Errors: 0, Invalid: 0
Start time: 2019-08-08 22:42:16Z
End time: 2019-08-08 22:42:17Z
Duration: 1.426 seconds
Interestingly, when I run them with --domain=Multiple
(which should be the default according to the docs) this happens:
D:\temp\Nunit.Test>nunit3-console.exe --domain=Multiple --noresult Test35\bin\Debug\Test35.dll Test40\bin\Debug\Test40.dll
NUnit Console Runner 3.10.0 (.NET 2.0)
Copyright (c) 2019 Charlie Poole, Rob Prouse
Freitag, 9. August 2019 00:47:15
Runtime Environment
OS Version: Microsoft Windows NT 10.0.18362.0
CLR Version: 4.0.30319.42000
Test Files
Test35\bin\Debug\Test35.dll
Test40\bin\Debug\Test40.dll
Test Run Summary
Overall result: Unknown
Test Count: 0, Passed: 0, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
Start time: 2019-08-08 22:47:16Z
End time: 2019-08-08 22:47:16Z
Duration: 0.477 seconds
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
Net picking wrong referenced assembly version
The problem is that you are referencing one of the telerik assemblies in your project which references another one that isn't there. First...
Read more >How the Runtime Locates Assemblies - .NET Framework
Learn how the common language runtime (CLR) locates and binds to the assemblies that make up your application in .NET.
Read more >Console and Engine Release Notes
NET 7 installed; #1178 Running tests with nunit3-console version 3.15.0 ... NET framework version when executing tests from multiple assemblies at once ......
Read more >How to resolve “Could not load file or assembly … or one of its ...
When we use multiple versions of same assembly, it is more likely to encounter this runtime exception. It is easy to resolve provided...
Read more >Problems with .NET unit testing
Run "dotnet --version" command. Log Files. Build your solution and then collect Rider logs: Help -> Collect Logs; Run Unit Tests if you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here’s the sample repository: https://github.com/PoByBolek/Nunit.Test
Fixed by #670