System.BadImageFormatException caused by NUnit project

前端 未结 10 1168
孤城傲影
孤城傲影 2020-12-10 02:03

Good day everyone. I have been having the same problem all day at work and am struggling to find any new paths to go down.

I am getting the following error when my

相关标签:
10条回答
  • 2020-12-10 02:13

    Check the target framework version of your assembly are same as nUnit test runner supports. See runFile.exe.config for list of supported runtimes.

    Also if you have megrated from FW 3 to FW 4, they has different runtime (CLR is different).

    0 讨论(0)
  • 2020-12-10 02:14

    A minor addition to all answers. You might need to change the NUnit runner platform (Resharper for me) itself as it was in my case. See example enter image description here

    0 讨论(0)
  • 2020-12-10 02:22

    I had this problem with a console app on X64 pc, the build was set as x86 and it still crashed. I went into Properties on the Console App and under build I changed my Platform Target from x86 to Any CPU then suddenly all the tests worked and ran successfully.

    of note, the Configuration Manager's platform field can "lie" to you and doesn't actually have to reflect what the project's properties are actually configured to do. My configuration manager said that "Common.dll" was being built as "Any CPU", but the project properties (the setting that really matters) was building it as "x86".

    enter image description here

    0 讨论(0)
  • 2020-12-10 02:24

    My situation was a bit different. The error appeared quite randomly after running a Unit Test that had been modified.

    I removed the test and the error went away.

    I recreated the test and the error came back.

    I renamed the test and the error went away.

    I renamed the test back and the problem did not happen again.

    Hope this helps!

    Ben

    0 讨论(0)
  • 2020-12-10 02:30

    This might sound stupid, but, check your project and processor architectures. In my case, I was running 64-bit tests on what I assumed was a 64-bit machine (since it was building 64-bit projects).

    Guess what? It was actually a 32-bit machine. So NUnit.exe ran as 32-bit (obviously), and can't understand 64-bit tests.

    The solution? Build a x86 and x64 version of your tests, and run the x86 ones on the x86 machines, and the x64 ones on the x64 machines.

    Obvious. But worth checking out.

    0 讨论(0)
  • 2020-12-10 02:31

    Make sure that this setting is correct: Test menu -> Test Settings -> Default Processor Architecture -> x64 / x86. It was incorrect in my case and it failed with the same issue.

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