Andrew Maddison


SQLite and NHibernate Have Defeated Me for Today...

I’m having a stab at setting up a (very) little ecommerce shop for a friend, and downloaded Suteki Shop by Mike Hadlow.

First impressions were good. I simply downloaded the full source from the read-only repo, built it in VS2010 (which required an install of MVC), tweaked the connection strings and ran the CreateDb console project. (I already had SQL 2008 express installed).

I could then build it in Visual studio, and fire up the website using Cassini, no problems. So I tried running the tests (from visual studio) which resulted in a fair number of failures (56 Failed, 332 Passed and 13 ignores to be precise). Of these, the majority were to do with initialising SQLite from Nhibernate, and it’s this that stumped me (never having used SQlite, and having only grazed NHibernate a little bit at work. The output from Resharper’s test runner looked something like this:

Suteki.Shop.StockControl.AddIn.Tests.Maps [MapsTestsSetupAndTeardown] : Failed

SetUp : FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

—-> NHibernate.HibernateException : Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
—-> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
—-> System.BadImageFormatException : Could not load file or assembly ‘System.Data.SQLite’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

Googling for answers throws up a lot of information, and it seems there are quite a lot of people having similar problems, and there are several different causes and solutions proffered. I’ve tried a few but without much luck.

First of all I attempted to install SQLite (although I’m still not sure this is necesarry, assuming it could instead have been incuded as some kind of reference). This is where the confusion begins, The SQLite download page has 19 (count ‘em) downloads to chose from. I’m on 64bit windows 7, and Suteki shop targets .Net 4, so that narrows the options down to a mere 4 choices - setup or binary, “mixed mode” or not. I stumped for the mixed mode setup. I guess this might have been wrong.

The web seems to suggest a config fix is often the way, so I’ve also tried adding an app.config to the test projects as follows with both of the two sections sugested by the internet.

<?xml version=1.0 encoding=utf-8 ?>
    <supportedRuntime version=v4.0 sku=.NETFramework,Version=v4.0 />
      <remove invariant=System.Data.SQLite/>
      <add name=SQLite Data Provider invariant=System.Data.SQLite description=.Net Framework Data Provider for SQLite type=System.Data.SQLite.SQLiteFactory, System.Data.SQLite/>

This hasn’t worked. And dinner’s ready. If I find a solution (or if anyone suggests one) I’ll try and be good and write an update.