Hello,

When trying to excute tests from my .net5 dll, I'm getting "BadImageFormatException: Could not load file or assembly" error.
Checking my dll info, I verified that it has ARM64 arch:

I also verified that my execution folder contains "nunit.framework.dll" and other nunit files
Following some of the project config:

For execution, I'm running the following command:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" mynet_ut5.dll

Did I do something wrong or did I miss something?

Hi @Hichem , welcome to Microsoft Q&A forum. Looks like this is an issue about platform architecture, did you select the correct solution platform before running the test?

If you create a new simple nunit test project and set it as ARM64, will this issue appear again?

Hi @Hichem , really sorry for delay in reply. I have checked the information(description) that you posted, and did some tests. I can reproduce your issue, looks like ARM64 Platform Target is not supported in unit test. If you try to use default setting(AnyCPU, x64…) and open Developer Command Prompt for VS 2019 > type cd XXXXX to redirect to the folder where your mynet_ut5.dll file saved > type vstest.console.exe mynet_ut5.dll will this issue disappear?

Hi @Tianyu Sun-MSFT , Thanks :)

As mentioned in my previous post, I'm using the console to execute my test without mentioning of the solution platform. The failure is happening on my Surface platform.

Also tried to create a new simple nunit project, but when I build it for ARM64, I'm getting an x86 dll:

Following the config of my new project:

I'm not able to get it for ARM64, I don't know what's wrong?

Hi again,

I was able to get it compiled for ARM64 by adding the following lines to the project file:

And still having the same issue:

C:\hichem\to_be_removed\net5.0-windows>"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" NUnitTestProject1.dll
Microsoft (R) Test Execution Command Line Tool Version 16.8.0

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
NUnit Adapter 3.16.1.0: Test execution started
Running all tests in C:\hichem\to_be_removed\net5.0-windows\NUnitTestProject1.dll
Assembly not supported: C:\hichem\to_be_removed\net5.0-windows\NUnitTestProject1.dll
Exception NUnit.Engine.NUnitEngineException, Exception thrown executing tests
An exception occurred in the driver while loading tests.
at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
at NUnit.Engine.Runners.DirectTestRunner.LoadPackage()
at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded()
at NUnit.Engine.Runners.DirectTestRunner.Explore(TestFilter filter)
at NUnit.Engine.Runners.MasterTestRunner.Explore(TestFilter filter)
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 236 at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunTests(IEnumerable 1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 104
Innerexception: System.BadImageFormatException: Could not load file or assembly 'NUnitTestProject1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. An attempt was made to load a program with an incorrect format.
File name: 'NUnitTestProject1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at NUnit.Engine.Drivers.NUnitNetStandardDriver.Load(String testAssembly, IDictionary`2 settings)
at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
NUnit Adapter 3.16.1.0: Test execution complete
No test is available in C:\hichem\to_be_removed\net5.0-windows\NUnitTestProject1.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

Additionally, path to test adapters can be specified using /TestAdapterPath command. Example /TestAdapterPath:<pathToCustomAdapters>.