【问题标题】:NUnit System.BadImageFormatException When Running Unit Tests运行单元测试时出现 NUnit System.BadImageFormatException
【发布时间】:2013-02-09 23:53:06
【问题描述】:

首先让我在这篇文章的开头说,我在 TeamCity 论坛和 SO 上看到了关于这个主题的各种讨论,但似乎没有什么对我有用。

我有一个 C#.Net 解决方案,并在 TeamCity 中配置了两个步骤,一个构建步骤和一个单元测试步骤。运行 NUnit 测试时,我在 TeamCity 中收到以下错误:

[步骤 2/2] 开始:
C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.NUnitLauncher.exe
#TeamCityImplicit [步骤 2/2] 在目录中:C:\TeamCity\buildAgent\work\trunk [步骤 2/2] 2013-02-23 18:00:11,827
[4972] 警告 JetBrains.TeamCity.Utils.PE.PEReader - 无法解析 程序集文件:可执行文件 (.exe) 或库 (.dll) 的格式为 [步骤 2/2] System.BadImageFormatException: 可执行文件的格式 (.exe) 或库 (.dll) 无效。 [步骤 2/2] 在
Mono.Cecil.PE.ImageReader.ReadImage() in
c:\BuildAgent\work\4fb4fc7600eac5a9\src\Utils\src\PE\ImageReader.cs:line 84 [步骤 2/2] 在
JetBrains.TeamCity.Utils.PE.PEReader.DescribeAssemblyRuntime(字符串 组装文件)在
c:\BuildAgent\work\4fb4fc7600eac5a9\src\Utils\src\PE\PEReader.cs:line 22 [步骤 2/2] 启动 TeamCity NUnit 测试运行程序 [步骤 2/2] 运行 .NET Framework v2.0 x64 下的 NUnit-2.6.2 测试 [步骤 2/2]
##teamcity[buildStatus text='NUnit error, {build.status.text}' status='ERROR'] [步骤 2/2] NUnit 在运行测试时出错
'...UnitTests.csproj' 程序集 正在为
编译加载程序集 无法解析程序集文件:可执行文件 (.exe) 的格式或 库 (.dll) 无效。 NUnit runner 运行时是 v2.0.50727, x64
System.BadImageFormatException:无法加载文件或程序集
'...UnitTests.csproj' 或其依赖项之一。进行了一次尝试 加载格式不正确的程序。文件名:
'....UnitTests.csproj' ---> System.BadImageFormatException: 不能 加载文件或程序集“....UnitTests.csproj”或其之一 依赖关系。试图加载一个不正确的程序 格式。文件名:'....UnitTests.csproj'

我正在运行 TeamCity 7.1.4。我正在使用 Visual Studio 2012,我当前的配置是 64 位。我正在使用 nunit 2.62 运行时版本 2.0。

我已按如下方式配置了我的 TeamCity 设置:

MSBuild 步骤: .NET 框架 4.5 运行平台:x64

NUnit 步骤: NUnit 跑步者:2.6.2 .NET 运行时:平台 x64 版本:v2.0

使用 resharper 运行时,单元测试全部通过。

知道 BadImageFormatExceptions 通常与在 x86 中编译 64 位项目有关,反之亦然,我已经为解决方案的配置管理器以及团队中的各种设置尝试了几乎所有 64/x86 设置组合城市。似乎无论我的设置如何,我都会收到此错误。有人有什么想法吗?

【问题讨论】:

  • BadImageFormatException 也可能意味着您正在尝试加载不是 .Net 程序集的文件。错误消息表明您正在尝试加载 UnitTests.csproj,而不是程序集。

标签: c# .net nunit teamcity


【解决方案1】:

感谢@adrianbanks 在这方面。原来我指向 .csproj 文件来执行测试。根据 Adrian,我将 TeamCity 配置为指向单元测试 dll,一切正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 2011-06-07
    • 1970-01-01
    • 2013-01-01
    • 1970-01-01
    • 2021-12-05
    相关资源
    最近更新 更多