FluentNHibernate SQLite configuration exception - after switching to .net4

Posted by stiank81 on Stack Overflow See other posts from Stack Overflow or by stiank81
Published on 2010-04-27T08:54:54Z Indexed on 2010/04/27 9:03 UTC
Read the original article Hit count: 442

I get an exception thrown when trying to use Fluent to configure my NHibernate connection to SQLite. The code I use to configure is as follows:

var cfg = Fluently.Configure().
             Database(SQLiteConfiguration.Standard.ShowSql().UsingFile("MyDb.db")).
             Mappings(m => m.FluentMappings.AddFromAssemblyOf<MappingsPersistenceModel>());
_sessionFactory = cfg.BuildSessionFactory();     

A HibernateException is thrown when BuildSessionFactory() is called, saying:

Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.

It has an InnerException:

Exception has been thrown by the target of an invocation.

Which again has an InnerException:

The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use element in the application configuration file to specify the full name of the assembly.

Now - to me it sounds like it doesn't find System.Data.SQLite.dll, but I can't understand this. Everywhere this is referenced I have "Copy Local", and I have verified that it is in every build folder for projects using SQLite. I have also copied it manually to every Debug folder of the solution - without luck.

What can be causing this? Any ideas?

My suspicion is that it is related to .Net4 somehow. The reason is that it worked just fine when I used .Net3.5, and then I changed to .Net4, and the problem started. You can also check out this other question for a more general approach towards Fluent-.Net4 compatibility.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about fluent-nhibernate