2016-02-26 71 views
0

我正在開發一個使用SQLite數據庫的Xamarin應用程序,我們有單元測試來覆蓋此功能。Xamarin SQLite單元測試64位Windows

這些單元測試在OS X機器上執行並傳遞,但在Windows 8(64位)VM上(它在CI基礎結構內充當從機時)運行它們時,我們會看到與SQLite相關的錯誤。

我們看到這個錯誤來自NUnit的(2.6.4)當測試運行

ProcessModel: Default DomainUsage: Single 
Execution Runtime: net-4.5 
Unhandled Exception: 
System.BadImageFormatException: Could not load file or assembly 'App.Core.Tests, Version=1.0.5900.25009, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. 
File name: 'App.Core.Tests, Version=1.0.5900.25009, Culture=neutral, PublicKeyToken=null' 

Server stack trace: 
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 
at System.Reflection.Assembly.Load(AssemblyName assemblyRef) 
at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path) 
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites) 
at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites) 
at NUnit.Core.TestSuiteBuilder.BuildSingleAssembly(TestPackage package) 
at NUnit.Core.TestSuiteBuilder.Build(TestPackage package) 
at NUnit.Core.SimpleTestRunner.Load(TestPackage package) 
at NUnit.Core.ProxyTestRunner.Load(TestPackage package) 
at NUnit.Core.ProxyTestRunner.Load(TestPackage package) 
at NUnit.Core.RemoteTestRunner.Load(TestPackage package) 
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs) 
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Object[]& outArgs) 
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg) 

Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
at NUnit.Core.TestRunner.Load(TestPackage package) 
at NUnit.Util.TestDomain.Load(TestPackage package) 
at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options) 
at NUnit.ConsoleRunner.Runner.Main(String[] args) 

這是關係到使用64位Windows的事實?

+0

看來你想在x86進程上加載x64庫... – Gusman

回答

2

BadImageFormat幾乎總是因爲運行過程的位數和相關程序集的位數之間不匹配。正如你可能知道的,Sqlite不是AnyCPU,而是x86或x64。很可能您的測試套件是經過編譯的AnyCPU,但您使用的是32位版本的Sqlite。

NUnit 3會自動檢測您的測試套件(但不依賴程序集)的位數並正確運行。 NUnit 2不會,你必須相應地運行你的測試。從NUnit 2.6文檔,

nunit控制檯程序的.NET 2.0版本是使用/ platform:anycpu構建的,它使得它被jit編譯爲32位系統上的32位代碼和64位系統上的64位代碼。當使用NUnit在64位系統上測試32位應用程序時,這會導致異常。爲避免此問題,請在64位系統上測試32位代碼時使用使用/ platform:x86構建的nunit-console-x86程序。

寫得不好,我們應該修復它,但我會推薦兩件事;

  1. 確保您的試件的目標在x86/x64如果您正在使用的x86匹配sqlite的
  2. ,與NUnit控制檯-x86.exe程序運行測試
+0

太棒了!感謝您的步驟解決問題後的快速響應, – user3617723