BadImageFormatException when running unit tests on build server

前端 未结 1 940
别那么骄傲
别那么骄傲 2021-01-26 16:44

I have a suite of NUnit tests in a project with AnyCPU architecture. Some of these tests use types from an x86 (32-bit) assembly.

When I run the tests locally (via ReSha

相关标签:
1条回答
  • 2021-01-26 17:46

    nunit3-console MyProject.csproj runs the tests in 64-bit process by default, which make it impossible to load 32-bit assemblies. This doesn't have anything to do with build server, so the same would happen on TeamCity etc.

    The solution is to force the runner to use 32-bit process by adding a proper flag: nunit3-console MyProject.csproj --x86.

    Analogous problem with xUnit can be solved by running dotnet xunit -x86.

    I think that for dotnet test the command dotnet test --runtime win10-x86 (with proper system flag) would help.

    Why the tests don't fail in ReSharper?

    ReSharper test runner by default automatically chooses the "bittedness" of the process. Maybe it analyses assembly references in test files, I don't know. Anyway, in my case it was choosing 32-bit runner for my unit tests. When I forced it to use 64-bit (Unit Test Sessions —> Options —> Platform —> x64), a few tests failed with same message as on Jenkins.

    0 讨论(0)
提交回复
热议问题