【发布时间】:2011-11-21 14:27:11
【问题描述】:
我浏览了 stackoverflow 上说明的几个 nunit 和 Visual Studio 问题,但找不到适合我的案例的任何线程。
我正在使用 NUnit 测试我编写的一些代码,我正在将我的 testproject 的 *.csproj 文件加载到 NUnit GUI 工具中。
我想出了我猜的问题,但到目前为止我没有解决方案。 我在做什么:
我引用了另外 2 个项目,它们都是 dll 项目。 这意味着我有 3 个项目:TestProject (DLL)、SettingsManager(DLL)、DatabaseInterface (DLL)。所有这些都在一个解决方案中。 DatabaseInterface 项目包含对另一个 C++ x86 DLL 的本机 api 调用,但没有通过“using”语句显式引用此 DLL。
两者之一是 SettingsManager,存储一些配置数据,如路径等,但无论如何。 Testproject 和 DatabaseInterface 都引用了 SettingsManager。
所有 3 个项目都在“Debug”和“AnyCPU”下构建。在我的 TestProject 中仅引用和使用 SettingsManager 工作正常,但是当我添加 DatabaseInterface 时,我收到 BadImageFormatException 告诉我它正在尝试加载格式错误的文件。
为了让它更明显,这是有效的:
using myNamespace.Settings; // contains SettingsManager
using System;
using NUnit.Framework;
namespace myNamespace.myTestProject
{
[TestFixture]
public class TestProject
{
[SetUp]
public void SetUp()
{
}
[Test]
public void ReadDbFile()
{
string s = SettingsManager.DbFile; // gets the path of the db file
}
}
}
NUnit 输出:
这不起作用:
using myNamespace.Settings; // contains SettingsManager
using myNamespace.DbInterface; // contains DatabaseInterface, which contains native calls to C++ dll
using System;
using NUnit.Framework;
namespace myNamespace.myTestProject
{
[TestFixture]
public class TestProject
{
DatabaseInterface instance = null;
[SetUp]
public void SetUp()
{
}
[Test]
public void ReadDbFile()
{
string s = SettingsManager.DbFile; // gets the path of the db file
}
}
}
第二次尝试,包含
using myNamespace.DbInterface;
抛出一个 myNamespace.myTestProject.TestProject(TestFixtureSetUp): SetUp : System.BadImageFormatException : Die Datei oder Assembly "DatabaseInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" 或未找到参考。尝试加载格式错误的文件。”
即使所有 3 个项目都是使用 Debug 和 AnyCPU 构建的。
我正在使用标准的 *.config 文件,例如 NUnit Testproject 之一。也许有些人对此有误。
到目前为止,是否有人在尝试从另一个 DLL 加载代码时遇到同样的错误? 两个项目(测试和数据库)都引用 SettingsManager DLL 会不会是个问题? 我是不是做错了什么大事?
我在所有 3 个项目中仔细检查了我的构建配置,但找不到任何可能错误的设置并解释了 BadImageFormatException。
【问题讨论】:
标签: c# .net visual-studio nunit