Build/Test Issues

x86 vs x64 (Sqlite)

Started by brian on 11,042 views

Our sqlite tests fail with ncrunch but work with Resharper and nunit. See test results from ncrunch below. Sqlite is compiled for a specific architecture. So there are different binaries for x86 vs x64. We are using x64 and have set our projects to build as "Any CPU" on our x64 machines. When we get this wrong, sqlite give us a very similar exception. So my guess is ncrunch is either building the solution as x86 or is running the test as x86.



SetUp : System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at System.Data.SQLite.UnsafeNativeMethods.sqlite3_open_interop(Byte[] utf8Filename, Int32 flags, IntPtr& db)
at System.Data.SQLite.SQLite3.Open(String strFilename, SQLiteOpenFlagsEnum flags, Int32 maxPoolSize, Boolean usePool) in c:\work\SQLite\dotnet\System.Data.SQLite\SQLite3.cs:line 126
at System.Data.SQLite.SQLiteConnection.Open() in c:\work\SQLite\dotnet\System.Data.SQLite\SQLiteConnection.cs:line 842
at NHibernate.Connection.DriverConnectionProvider.GetConnection()
at NHibernate.Tool.hbm2ddl.ManagedProviderConnectionHelper.Prepare()
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(IDictionary`2 cfgProperties)
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.QuoteTableAndColumns(Configuration configuration)
at

Edited

Hi Brian,

Thanks for posting :)

NCrunch builds to whatever platform you've configured your project files to, though the test runner is currently fixed to run things as x86. x64 support is still coming.


Cheers,

Remco
For anyone interested, x64 support was introduced in the 1.35b build that was released this morning.
Hi,

I'm having trouble working with SQLite on x64.

I'm editing the NCrunch configuration for all my projects to Use CPU Architecture= x64 (if I don't, I get BadImageFormatException for the SQLite dlls).

I think now it's failing to load the x64 build of the referenced projects? Tests run fine when using Resharper and AnyCPU build config.

(Technesis.Gateway is one of the projects in the solution.)

SetUp : System.BadImageFormatException : Could not load file or assembly 'Technesis.Gateway, 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.
----> System.BadImageFormatException : Could not load file or assembly 'file:///C:\Users\Dan\AppData\Local\NCrunch\9640\32\Technesis.Gateway\bin\Debug\Technesis.Gateway.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format.
TearDown : System.BadImageFormatException : Could not load file or assembly 'file:///C:\Users\Dan\AppData\Local\NCrunch\9640\32\Technesis.Gateway\bin\Debug\Technesis.Gateway.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format.
at Technesis.Gateway.UnitTests.ServiceTests.InMemoryDatabaseTextFixture.Setup()
--BadImageFormatException
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at nCrunch.Common.CustomAssemblyResolver.ResolveAssemblyWithShortName(String shortAssemblyName)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
--TearDown
at Technesis.Gateway.UnitTests.ServiceTests.InMemoryDatabaseTextFixture.TearDown()

Edited

Hi, thanks for posting!

The test environment used by NCrunch needs to be either a 32-bit OR a 64-bit environment (NCrunch does not use AnyCPU). This means that you will need to be certain of the format of the assemblies that you are loading into your test environment, as it isn't possible to have a test environment that hosts both 32-bit and 64-bit assemblies.

The 'Use CPU Architecture' setting is only applicable to test projects that are built with a target platform of 'AnyCPU'. Where this is not the case, NCrunch will simply set up the test environment according to the default target platform configured inside the test project's .proj file.

Something to watch out for is that NCrunch will only use the target platform that is specified in the DEFAULT build configuration inside a .proj file - it will ignore the build configuration you've selected in the top dropdown box of Visual Studio. This means that if you've created a custom build configuration (i.e. 'Debug-x64') which specifies a target platform of x64, and you have this selected in your IDE, then NCrunch may not be using the target platform specified in this configuration although other test runners probably would (because that was how you built the assemblies). Always make sure that you have a sensible default build configuration specified in each of your project files when using NCrunch.

I hope this helps!


Cheers,

Remco

Edited

Post a reply

Log in to reply.