簡體   English   中英

使用 NUnit 和 Resharper 時出現 System.BadImageFormatException

[英]System.BadImageFormatException while using NUnit and Resharper

我正在使用 Visual Studio 2010 和 Resharper 9.0。 我有64位系統。 我有 NUnit 2.6.4

當我嘗試運行任何測試時,我會得到這個。 這里沒有測試工作。 誰能告訴我如何解決這個錯誤。

錯誤:

System.BadImageFormatException : Could not load file or assembly 'NUnitFirst, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

這很可能是因為當您的生產代碼需要 32 位時,您的測試程序集被編譯為 64 位,反之亦然。 ReSharper 的測試運行器將根據您的測試程序集(.net 4.0 或 4.5、32 或 64 位等)啟動托管進程。 如果項目被標記為 32 位、64 位或 AnyCPU,它會啟動相應的托管應用程序。

如果您的生產程序集需要例如 64 位,但您的測試程序集是 32 位,則啟動 32 位測試托管應用程序,並且無法加載生產程序集,並拋出BadImageFormatException

解決方案是更改測試組件的位數以匹配生產組件。

如果你編譯為 x64 位使用nunit.exe否則使用nunit-x86.exe

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM