SQLite NHibernate configuration with .Net 4.0 and vs 2010

I am updating this post with what I think I now know about setting up this configuration; HOWEVER, there is more to know, since I still have a problem, this is one important area.

I am using SQLite for unit testing, which now works just fine using the setup steps below. I also use it when I need a test run of the user interface with more data than in the test data in memory, but without SQLServer overhead - this configuration does not work with the following:

{"Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4."} 

Here is updated information about the configurations that DO work:

1) What is SQLite dll ?? There are some bad links that look useful, but that have build errors in them . The only good download from this date is here at Source Forge . v1.066, which was released today, 4-18-2010.

2) Should you use the GAC? No, as Maurizio answered.

3) x64 builds - as Maurizio answered.

4) NHib driver - SQLite20Driver, as Maurizio answered

5) FNH as a potential conflict - no, as Maurizio answered

Cheers
Berryl

== ADD'L DEBUG INFO ===

When the exception is removed, and I call the SQLite20Drive assembly, I get the following, which tells me that the driver should be available. However, I am interested, since the configuration code is in a different assembly.

- build on error ----

  ?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 & 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 & Master\\Documents\\Projects\\Smack\\trunk\\src\\ConstructionAdmin.WpfPresentation\\bin\\Debug\\NHibernate.dll" ManifestModule: {NHibernate.dll} PermissionSet: {<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true"/> } ReflectionOnly: false SecurityRuleSet: Level1 

--- assembly during unit testing (NO ERROR)

 {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 & 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 & Master\\Documents\\Projects\\Smack\\trunk\\src\\ConstructionAdmin.Tests\\bin\\Debug\\NHibernate.dll" ManifestModule: {NHibernate.dll} PermissionSet: {<PermissionSet class="System.Security.PermissionSet" 

version = "1" Unlimited = "true" / ">} ReflectionOnly: false SecurityRuleSet: Level1

Here is this boot script for this SQLite session:

  /// <summary>SQLite-NHibernate bootstrapper for general use.</summary> 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 => m.AutoMappings.Add(persistenceModel)); SessionFactory = fluentCfg.BuildSessionFactory(); Check.Require(SessionFactory.GetAllClassMetadata().Count > 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(); } } 

}

+4
source share
3 answers

I want this to stand out, to help someone else; the full reason for this is explained here ; so set up your congig to use BOTH to redirect to combos with the mixed boot mode referenced by Mauricio.

+1
source
  • Of course. You can also use previous versions if you configure mixed mode loading .
  • No need to be in the GAC. You can use gacutil to remove assemblies from the GAC.
  • Use x64 DLL to install on Windows x64 and x86 for Windows x86
  • Please post a full trace of the exception stack. Also, if you are using build 3.5, use mixed-mode loading .
  • FNH has no SQLite reference.
+5
source

I had the same problem and found little help or didn't help at all on all forums and blogs.

Please note that this issue is relevant for all of the following criteria: - using SQLite - with System.Data.SqlLite - on an x64 machine - and NHibernate (2.1.2.4 in my case)

This piece of configuration in my web.config (or app.config for my unit tests) made it work. I had to qualify the assembly to make sure it loaded correctly.

 <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <qualifyAssembly partialName="System.Data.SQLite" fullName="System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64" /> </assemblyBinding> </runtime> </configuration> 

Somewhere inside it, plumbing, during display using scanned assemblies, NHibernate creates an Assembly object using its name paritla, in the form of the string "System.Data.SQLite". One way or another, the x86 build version was loaded.

In the above configuration, ensure that using the partial name to load the assembly will provide x64 version.

EDIT: I am using version 1.0.66.0 and took the DLL under the bin \ x64 folder in the SQLite-1.0.66.0-binaries.zip file, available on sourceforge.

0
source

Source: https://habr.com/ru/post/1307087/


All Articles