我瀏覽了幾個nunit和visual studio的問題陳述在stackoverflow上,但無法找到任何線程,我的情況適合。NUnit C#測試項目引用其他DLL
我使用NUnit來測試我寫的一些代碼,我將我測試項目的* .csproj文件加載到NUnit GUI工具中。
我想出了我猜想的問題,但到目前爲止我還沒有解決。 我在做什麼:
我參考2個其他項目都是DLL項目。 這意味着我有3個項目:TestProject(DLL),SettingsManager(DLL),DatabaseInterface(DLL)。所有都在一個解決方案。 DatabaseInterface項目包含對另一個C++ x86 DLL的本機API調用,但不通過「using」語句顯式引用此DLL。
其中之一是SettingsManager,存儲一些配置數據,如路徑&等,但無論如何。 Testproject和DatabaseInterface都引用了SettingsManager。
所有3個項目都在「調試」和「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:死於程序集「DatabaseInterface,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null」或未找到引用。它試圖加載錯誤格式的文件。」
即使所有3個項目的建設使用調試和AnyCPU。
我使用了一個標準的* config文件,如NUnit的Testproject之一。也許有些是不對的。
有沒有人遇到過同樣的錯誤嘗試從另一個DLL加載代碼這麼遠? 可以說,它是這兩個項目(測試&數據庫)引用的一個問題SettingsManager DLL? 我是否做重大錯事?
我雙重檢查我的構建配置中的所有3個項目,但未能找到其可能是錯誤的任何設置,並解釋了BadImageFormatException。
可能是我猜測的問題。因爲我使用的是64位Win7,所以「AnyCPU」的意思是64Bit以後。這是32位編譯的DatabaseInterface DLL的錯誤。 – inva