question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BadImageFormatException from testhost.dll when using Visual Studio 2022 Preview

See original GitHub issue

I 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
  • What .net platform and version is being targeted
    • .NET 6.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
OsirisTerjecommented, Jan 20, 2022

Thanks! I’ve also notified @kendrahavens MS-PG directly.

1reaction
OsirisTerjecommented, Jan 20, 2022

@Stolpe Just tried it here with Preview 3, and it worked here too, and in the net60 branch.

image

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found