2012-09-19 88 views
4

我安裝了NUnit 2.6.1並嘗試在Windows 7 x64上運行一個簡單的測試。它導致異常無法運行NUnit測試

嘗試加載格式不正確的程序。您 可能會嘗試加載使用CLR的更高版本的 版本構建的程序集,而不是NUnit當前運行的版本 (2.0.50727)或嘗試將64位程序集加載到32位進程中。

這是很奇怪,因爲nunit.exe.config看起來像下面

<?xml version="1.0" encoding="utf-8" ?> 
- <configuration> 
- <!-- 
    The GUI only runs under .NET 2.0 or higher. The 
    useLegacyV2RuntimeActivationPolicy setting only 
    applies under .NET 4.0 and permits use of mixed 
    mode assemblies, which would otherwise not load 
    correctly. 


    --> 
- <startup useLegacyV2RuntimeActivationPolicy="true"> 
- <!-- Comment out the next line to force use of .NET 4.0 
    --> 
- <!-- <supportedRuntime version="v2.0.50727" /> 
    --> 
    <supportedRuntime version="v4.0.30319" /> 
    </startup> 
- <runtime> 
- <!-- Ensure that test exceptions don't crash NUnit 
    --> 
    <legacyUnhandledExceptionPolicy enabled="1" /> 
- <!-- Run partial trust V2 assemblies in full trust under .NET 4.0 
    --> 
    <loadFromRemoteSources enabled="true" /> 
- <!-- Look for addins in the addins directory for now 
    --> 
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
    <probing privatePath="lib;addins" /> 
    </assemblyBinding> 
    </runtime> 
    </configuration> 

回答

7

這聽起來並不像NUnit的一個問題。這聽起來像你的單元測試程序集不是爲32位處理而構建的。你確定你的單元測試程序集是爲32位構建的嗎?如果NUnit運行32位,並且您的程序集構建在64位(或不構建爲任何CPU),則會出現此問題。調用應用程序確定程序集所需的位深度。你不能使用32位進程的64位DLL,反之亦然。

我提到這個的唯一原因是因爲你的問題說你試圖運行測試。如果NUnit配置不正確,甚至不會啓動。

+0

不理解你。 NUnit是64位,對吧?我的系統也是64位,我需要測試的程序也是64位。問題在哪裏? – Alexandre

+2

問題是你正在構建64位DLL,但在32位模式下運行NUnit。你確定你正在運行64位的NUnit嗎?有一個單獨的64位可執行文件。或者你是這樣做的,你正在運行64位的NUnit並加載32位的DLL。無論哪種方式是不匹配的,它不高興 – devshorts

+0

不,我不是。我如何在64模式下運行它(NUnit)? 「或者你是這樣做的,你正在運行64位的NUnit並加載32位的dll。」其實,我不知道。我怎麼知道它? – Alexandre