First let me preface this post by saying that I have seen various discussions on this topic within the TeamCity forums and here on SO, yet nothing seems to work for me.
I have a C#.Net solution and have configured two steps within TeamCity, a build step and a unit test step. When running the NUnit test I get the following error in TeamCity:
[Step 2/2] Starting:
C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.NUnitLauncher.exe
#TeamCityImplicit [Step 2/2] in directory: C:\TeamCity\buildAgent\work\trunk [Step 2/2] 2013-02-23 18:00:11,827
[4972] WARN JetBrains.TeamCity.Utils.PE.PEReader - Failed to parse assembly file: Format of the executable (.exe) or library (.dll) is [Step 2/2] System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid. [Step 2/2] at
Mono.Cecil.PE.ImageReader.ReadImage() in
c:\BuildAgent\work\4fb4fc7600eac5a9\src\Utils\src\PE\ImageReader.cs:line 84 [Step 2/2] at
JetBrains.TeamCity.Utils.PE.PEReader.DescribeAssemblyRuntime(String assemblyFile) in
c:\BuildAgent\work\4fb4fc7600eac5a9\src\Utils\src\PE\PEReader.cs:line 22 [Step 2/2] Start TeamCity NUnit Test Runner [Step 2/2] Running NUnit-2.6.2 tests under .NET Framework v2.0 x64 [Step 2/2]
##teamcity[buildStatus text='NUnit error, {build.status.text}' status='ERROR'] [Step 2/2] NUnit error running tests in
'...UnitTests.csproj' assembly Loading assembly is compiled for
Failed to parse assembly file: Format of the executable (.exe) or library (.dll) is invalid. NUnit runner runtime is v2.0.50727, x64
System.BadImageFormatException: Could not load file or assembly
'...UnitTests.csproj' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name:
'....UnitTests.csproj' ---> System.BadImageFormatException: Could not load file or assembly '....UnitTests.csproj' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: '....UnitTests.csproj'
I am running TeamCity 7.1.4. I am using Visual Studio 2012, and my current configuration is 64 bit. I am using nunit 2.62 runtime version 2.0.
I have configured my TeamCity settings as follows:
MSBuild Step: .NET Frameworrk 4.5 Run Platform: x64
NUnit Step: NUnit Runner: 2.6.2 .NET Runtime: Platform x64 Version: v2.0
The unit tests all pass when run with resharper.
Knowing that BadImageFormatExceptions are usually related to compiling a 64 bit project in x86 or vice versa, I have tried just about every combination of 64/x86 settings for both my configuration manager for the solution, as well as the various settings within team city. It seems like regardless of my settings, I get this error. Anyone have any ideas?
BadImageFormatException
can also mean that you are attempting to load a file that is not a .Net assembly. The error message suggests that you are trying to loadUnitTests.csproj
, not an assembly. – adrianbanks