BadImageFormatException from testhost.dll when using Visual Studio 2022 Preview
See original GitHub issueI am unable to run NUnit tests on the latest Visual Studio 2022 Preview. I get the following error, which I don’t know is due to a bug in the Preview, or a sign of changes to inevitably come.
Log level is set to Informational (Default).
Connected to test environment '< Local Windows Environment >'
Test data store opened in 0,159 sec.
========== Starting test discovery ==========
========== Test discovery skipped: All test containers are up to date ==========
Starting test discovery for requested test run
========== Starting test discovery ==========
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process exited with error: Unhandled exception. System.BadImageFormatException: Could not load file or assembly 'C:\Source\NUnitExplicitTest\Tests\bin\Debug\net6.0\testhost.dll'. An attempt was made to load a program with an incorrect format.
File name: 'C:\Source\NUnitExplicitTest\Tests\bin\Debug\net6.0\testhost.dll'
. Please check the diagnostic logs for more information.
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited(Boolean testHostExited)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)
========== Test discovery aborted: 0 Tests found in 2,6 sec ==========
========== Starting test run ==========
Testhost process exited with error: Unhandled exception. System.BadImageFormatException: Could not load file or assembly 'C:\Source\NUnitExplicitTest\Tests\bin\Debug\net6.0\testhost.dll'. An attempt was made to load a program with an incorrect format.
File name: 'C:\Source\NUnitExplicitTest\Tests\bin\Debug\net6.0\testhost.dll'
. Please check the diagnostic logs for more information.
Testhost process exited with error: Unhandled exception. System.BadImageFormatException: Could not load file or assembly 'C:\Source\NUnitExplicitTest\Tests\bin\Debug\net6.0\testhost.dll'. An attempt was made to load a program with an incorrect format.
File name: 'C:\Source\NUnitExplicitTest\Tests\bin\Debug\net6.0\testhost.dll'
. Please check the diagnostic logs for more information.
========== Test run aborted: 0 Tests (0 Passed, 0 Failed, 0 Skipped) run in < 1 ms ==========
- NUnit and NUnit3TestAdapter versions
- NUnit 3.13.2
- NUnit3TestAdapter 4.2.0
- Visual Studio edition and full version number (see Help About)
- Microsoft Visual Studio Enterprise 2022 (64-bit) - Preview Version 17.1.0 Preview 3.0
- A short repro, preferably attached or pointing to a git repo or gist
- https://github.com/Stolpe/NUnitExplicitTest/tree/net60 (I lazily reused a repo from an earlier issue 😃)
- What .net platform and version is being targeted
- .NET 6.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
System.BadImageFormatException caused by NUnit project
My situation was a bit different. The error appeared quite randomly after running a Unit Test that had been modified. I removed the...
Read more >Unable to debug unit tests
When I try to debug unit tests, I get error messages about not being able to load various system dlls. 'testhost.exe' (CLR v4.0.30319: ......
Read more >How to fix System.BadImageFormatException
I have a project with a method that uses a DLL from another project. It used to work just fine, but now when...
Read more >System.BadImageFormatException : Could not load file or ...
Hi, I am referencing X64 Clr:Core .Net Core5 C++/CLI dll in an C# Test application when running tests there is error ...
Read more >BadImageFormatException Class (System)
The exception that is thrown when the file image of a dynamic link library (DLL) or an executable program is invalid.
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

Thanks! I’ve also notified @kendrahavens MS-PG directly.
@Stolpe Just tried it here with Preview 3, and it worked here too, and in the net60 branch.