Category Archives: maven

Dependency management

NPanday nunit BadImageFormatException

Having got maven to build my C# project including unit tests on my developer machine, I was disheartened to be thwarted by a new lot of errors on the build server.

I took over this project from another developer and so was not certain what the state server configuration was in.

nunit executable in the PATH

The first hurdle was realising that the nunit executable must have it’s location included in the server’s PATH environment variable.

HOORAH, I thought.  Now I can move on.

Yeah right!

BadImageFormatException

The unit tests still wouldn’t build.  The next error was

ProcessModel: Default DomainUsage: Single
Execution Runtime: Default
Unhandled Exception:
System.BadImageFormatException: Could not load file or assembly 'BBCNewsI.MPS.Tests, Version=2.2.3.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'BBCNewsI.MPS.Tests, Version=2.2.3.0, Culture=neutral, PublicKeyToken=null'

😥

Why couldn’t maven see my test project??  I can see it!  After looking in a lot of wrong places I found the answer.  Nunit was running the tests as 64 bit because the build server is 64 bit.  As the code is dot net 2.0 and built as 32 bit, this is not good.

Maven pom.xml file

Again I looked in the wrong place.  The fix for this is not in nunit but in your maven pom file.  You need to force the tests to be run as 32 bit by adding this parameter:

forceX86

So here is how to describe your test.  In your pom file, add the parameter to the maven-test-plugin:

<plugin>
<groupId>org.apache.npanday.plugins</groupId>
<artifactId>maven-test-plugin</artifactId>
<version>1.4.0-incubating</version>
<configuration>
<forceX86>true</forceX86>
<integrationTest>true</integrationTest>
</configuration>
</plugin>