title: SQLite NHibernate configuration with .Net 4.0 and vs 2010
body: <p>I am updating this post with what I think I now know about getting this configuration; HOWEVER, there is more to know as I am still having a problem is one crucial area.</p>
  
  <p>I use SQLite for unit testing, which now works fine, using the configuration steps below. I also use it when I want a test run of the UI with more data than in-memory test data but without the overhead of SQLServer - this configuration fails with the following:</p>
  
  <pre><code>{"Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4."}
  </code></pre>
  
  <p>Here is updated info on configs that DO work:</p>
  
  <p>1) Which SQLite dll?? <b>There are some bad links out there that look helpful but that have build errors in them</b>. The <em>only</em> good download as of this date is <a href="http://sourceforge.net/projects/sqlite-dotnet2/files/SQLite%20for%20ADO.NET%202.0/1.0.66.0/SQLite-1.0.66.0-binaries.zip/download" rel="nofollow noreferrer">here at Source Forge</a>. v1.066 which was released today, 4-18-2010.</p>
  
  <p>2) Must you use the GAC? No, as answered by Mauricio.</p>
  
  <p>3) x64 builds - as answered by Mauricio.</p>
  
  <p>4) NHib driver - SQLite20Driver, as answered by Mauricio</p>
  
  <p>5) FNH as a potential conflict - no, as answered by Mauricio</p>
  
  <p>Cheers,<br>
  Berryl</p>
  
  <p>== ADD'L DEBUG INFO ===</p>
  
  <p>When the exception is hit and I call up the SQLite20Drive assembly, I get the following which suggests to me that the driver <em>should</em> be available. I am wondering though, as the configuration code is in a different assembly.</p>
  
  <p>-- assembly when error ----</p>
  
  <pre><code>    ?typeof(SQLite20Driver).Assembly
  {NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4}
  [System.Reflection.RuntimeAssembly]: {NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4}
  CodeBase: "file:///C:/Users/Lord &amp; Master/Documents/Projects/Smack/trunk/src/ConstructionAdmin.WpfPresentation/bin/Debug/NHibernate.DLL"
  EntryPoint: null
  EscapedCodeBase: "file:///C:/Users/Lord%20%26%20Master/Documents/Projects/Smack/trunk/src/ConstructionAdmin.WpfPresentation/bin/Debug/NHibernate.DLL"
  Evidence: {System.Security.Policy.Evidence}
  FullName: "NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4"
  GlobalAssemblyCache: false
  HostContext: 0
  ImageRuntimeVersion: "v2.0.50727"
  IsDynamic: false
  IsFullyTrusted: true
  Location: "C:\\Users\\Lord &amp; Master\\Documents\\Projects\\Smack\\trunk\\src\\ConstructionAdmin.WpfPresentation\\bin\\Debug\\NHibernate.dll"
  ManifestModule: {NHibernate.dll}
  PermissionSet: {&lt;PermissionSet class="System.Security.PermissionSet"
  version="1"
  Unrestricted="true"/&gt;
  }
  ReflectionOnly: false
  SecurityRuleSet: Level1
  </code></pre>
  
  <p>--- assembly when unit testing (NO ERROR)</p>
  
  <pre><code>{NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4}
  [System.Reflection.RuntimeAssembly]: {NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4}
  CodeBase: "file:///C:/Users/Lord &amp; Master/Documents/Projects/Smack/trunk/src/ConstructionAdmin.Tests/bin/Debug/NHibernate.DLL"
  EntryPoint: null
  EscapedCodeBase: "file:///C:/Users/Lord%20%26%20Master/Documents/Projects/Smack/trunk/src/ConstructionAdmin.Tests/bin/Debug/NHibernate.DLL"
  Evidence: {System.Security.Policy.Evidence}
  FullName: "NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4"
  GlobalAssemblyCache: false
  HostContext: 0
  ImageRuntimeVersion: "v2.0.50727"
  IsDynamic: false
  IsFullyTrusted: true
  Location: "C:\\Users\\Lord &amp; Master\\Documents\\Projects\\Smack\\trunk\\src\\ConstructionAdmin.Tests\\bin\\Debug\\NHibernate.dll"
  ManifestModule: {NHibernate.dll}
  PermissionSet: {&lt;PermissionSet class="System.Security.PermissionSet"
  </code></pre>
  
  <p>version="1"
  Unrestricted="true"/>
  }
      ReflectionOnly: false
      SecurityRuleSet: Level1</p>
  
  <p>Here is the bootstrapper for this a SQLite session:</p>
  
  <pre><code>    /// &lt;summary&gt;SQLite-NHibernate bootstrapper for general use.&lt;/summary&gt;
  public class SQLiteBoot : IDisposable
  {
      public readonly ISessionFactory SessionFactory;
      private readonly ISession _session;
      private static Configuration _config;
      private static string _persistenceModelGeneratorName;
  
      public SQLiteBoot(IAutoPersistenceModelGenerator persistenceModelGenerator) {
          if (_isSessionFactoryBuildRequired(persistenceModelGenerator)) {
              _config = new Configuration()
                  .SetProperty(ENV.ReleaseConnections, "on_close")
                  .SetProperty(ENV.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName)
                  .SetProperty(ENV.ConnectionDriver, typeof (SQLite20Driver).AssemblyQualifiedName)
                  .SetProperty(ENV.ConnectionString, "data source=:memory:")
                  .SetProperty(ENV.ProxyFactoryFactoryClass, typeof (ProxyFactoryFactory).AssemblyQualifiedName)
                  .SetProperty(ENV.CurrentSessionContextClass, typeof (ThreadStaticSessionContext).AssemblyQualifiedName);
  
              _persistenceModelGeneratorName = persistenceModelGenerator.Name;
              var persistenceModel = persistenceModelGenerator.Generate();
              var fluentCfg = Fluently.Configure(_config).Mappings(m =&gt; m.AutoMappings.Add(persistenceModel));
              SessionFactory = fluentCfg.BuildSessionFactory();
              Check.Require(SessionFactory.GetAllClassMetadata().Count &gt; 0, "No mapped classes - check your AutoPersistenceModel!");
  
          }
  
          _session = SessionFactory.OpenSession();
          CurrentSessionContext.Bind(_session);
  
          new SchemaExport(_config).Execute(true, true, false, _session.Connection, Console.Out);
      }
  
      private bool _isSessionFactoryBuildRequired(IAutoPersistenceModelGenerator persistenceModelGenerator)
      {
          return
              _config == null
              || SessionFactory == null
              || !persistenceModelGenerator.Name.Equals(_persistenceModelGeneratorName);
      }
  
      public void Dispose()
      {
          _session.Dispose();
      }
  }
  </code></pre>
  
  <p>}</p>