2016-02-26 30 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