Nunit is throwing a BadImageFormatException when trying to load tests for win-arm64 dll

Hichem 26 Reputation points
2021-05-04T15:39:05.247+00:00

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:
93641-arch64.png

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

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?

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
322 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
326 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Hichem 26 Reputation points
    2021-05-05T13:14:23.023+00:00

    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:

    93898-image.png

    Following the config of my new project:
    93937-image.png

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

    0 comments No comments

  2. Hichem 26 Reputation points
    2021-05-05T14:31:38.817+00:00

    Hi again,

    I was able to get it compiled for ARM64 by adding the following lines to the project file:
    94042-image.png

    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
    Copyright (c) Microsoft Corporation. All rights reserved.

    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, IGrouping2 testCases, TestFilter filter) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 236 at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunTests(IEnumerable1 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>.

    0 comments No comments

  3. Hichem 26 Reputation points
    2021-05-12T11:17:06.947+00:00

    Hi @Tianyu Sun-MSFT ,
    Thanks for the reply. Meanwhile I was able to solve the problem by using the right Build apps - SDK for win-arm64. I download it from here: https://dotnet.microsoft.com/download/dotnet/5.0