English 中文(简体)
NUnit C# Test Project referencing other DLL
原标题:NUnit C# Test Project referencing other DLL

我通过在 st流上说的努尼特和视力演播室问题而感染,但在我的案件适合的情况下,却找不到任何透镜。

Im利用NUnit测试一些代码I,I m把我测试项目的文件装入Unit GUI工具。

I figured out the problem I guess but I got no solution so far. What I m doing:

I reference 2 other projects both are dll projects. This means I got 3 projects: TestProject (DLL), SettingsManager(DLL), DatabaseInterface (DLL). All are in one solution. The DatabaseInterface project contains native api calls to another, C++ x86, DLL, but does not explicit reference this DLL via "using" statement.

两者都属于一种情形,储存一些配置数据,如道路和营地;等等。 测试项目和数据库Interface参考资料《背景》。

所有3个项目都以“建议”和“AnyCPU”为基础。 Referencing & using only the SettingsManager in my Test Project workvy but when, 我请我加上数据库Interface,我看上去一个BadImageFormatception告诉我,它试图装上带有错误格式的档案。

为了使之更加明显,工作单位:

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 Output:

这一工作:

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;

throws a myNamespace.myTestProject.TestProject(TestFixtureSetUp): SetUp : System.BadImageFormatException : Die Datei oder Assembly "DatabaseInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" or a reference was not found. It was tried to load a file of a wrong format."

即使所有3个项目都使用Debug和AnyCPU建造。

I m, using a standard *.config file, as the one of the NUnit Testproject. 也许有些人这样做是错误的。

Did anybody encountered the same error trying to load code from another DLL so far? Can it be a problem that both projects (Test & Database) reference the SettingsManager DLL ? Did I do something major wrong?

我在所有3个项目中两次核对了我的建筑组合,但未能找到任何可能错误的环境,并解释BadImageFormatException。

最佳回答

你们很可能使用努尼特语。 exe GUI 经营人,以万国邮联为目标。 该数据库将编入目标平台,我假定,自你重新提出这一问题以来,该平台为x64。 相反,利用Nnunit-x86.exe进行测试。 通用名称号码管理器的这个版本专门设计在32个轨道上运行,与您的<代码>数据库Inter图书馆依赖性兼容。

问题回答

这可能是一个依赖你们的问题。 如果你依赖Cat,即x86的未管理的图书馆,而且你正在使用x64。 在你试图在你的法典中使用这种依赖性之前,所有东西都将受到罚款。 BadImageFormatException。

为了克服这一点,你必须增加具体目标(x86或x64),并努力实现这一目标。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签