4

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.

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:

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

Here is updated info on configs that DO work:

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

2) Must you use the GAC? No, as answered by Mauricio.

3) x64 builds - as answered by Mauricio.

4) NHib driver - SQLite20Driver, as answered by Mauricio

5) FNH as a potential conflict - no, as answered by Mauricio

Cheers,
Berryl

== ADD'L DEBUG INFO ===

When the exception is hit and I call up the SQLite20Drive assembly, I get the following which suggests to me that the driver should be available. I am wondering though, as the configuration code is in a different assembly.

-- assembly when 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 when 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" Unrestricted="true"/> } ReflectionOnly: false SecurityRuleSet: Level1

Here is the bootstrapper for this a 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();
    }
}

}

Aaronaught
  • 120,909
  • 25
  • 266
  • 342
Berryl
  • 12,471
  • 22
  • 98
  • 182
  • UPDATE: "System.Data.SQLite.SR.resources" is something that also fails SQLite's own packaged self tests (included w/ 1.065 zip download; it's the only failure out of 20 some odd tests). Anyone know what that resource is and where to get it?? – Berryl Apr 16 '10 at 21:49
  • have you seen http://mystuffisallhere.com/blog/post/2009/06/29/NHibernate-on-SQLite-30-e28093-a-workaround-for-e2809cCould-not-find-any-resources-appropriate-for-the-specified-culture-or-the-neutral-culturee2809d.aspx ? – Mauricio Scheffer Apr 18 '10 at 21:24
  • I had seen that one, and it turns out that some prior release had a build error. I updated the best link for downloading in my orginal-edited post. – Berryl Apr 19 '10 at 00:41
  • UPDATE: pls see end of post for more debug info – Berryl Apr 19 '10 at 02:20
  • ** answered [here](http://stackoverflow.com/questions/2697795/using-fluentnhibernate-with-net4) – Berryl May 05 '10 at 00:43
  • I rolled this question back to its previous version because the latest update made it useless. If you want to post what worked for you then post it as an **answer**. – Aaronaught Oct 03 '11 at 20:38

3 Answers3

5
  1. Sure. You can also use previous versions if you configure mixed mode loading.
  2. No need to be in the GAC. You can use gacutil to remove the assemblies from the GAC.
  3. Use the x64 DLL to target Windows x64 and x86 for Windows x86
  4. Please post the full exception stack trace. Also if you're using a 3.5 assembly use mixed mode loading.
  5. FNH has no reference to SQLite.
Community
  • 1
  • 1
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • Hi Mauricio. Awesome info so far, if not a fix yet. Tacked the stack trace at end of my post. When I changed the build to x64 from ANY CPU I got a loader exception. What a pain!! – Berryl Apr 16 '10 at 01:52
  • I switched dll and build to x86 versions again. Now I've got " ----> System.Resources.MissingManifestResourceException : Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "System.Data.SQLite.SR.resources" was correctly embedded or linked into assembly "System.Data.SQLite" at compile time, or that all the satellite assemblies required are loadable and fully signed." – Berryl Apr 16 '10 at 15:26
  • @Berryl, the SQLite dll from phxsoftware isn't built for AnyCPU since it contains an unmanaged dll. You need to change references, or edit the project file manually to add the conditional references. – Lasse V. Karlsen Apr 19 '10 at 03:01
  • @Lasse, I currently am using the x86 dll (with build setting on x86), and am still having the "can't create SQLite20Driver" error. Interestingly though, the latest v1.066 (I've posted the source forge link above) appears to be all managed. Thanks for the reply. – Berryl Apr 19 '10 at 03:33
1

I want this to stand out so it will help someone else; the full reason this happens is explained here; so adjust your congig to use BOTH the redirect there in combo with the mixed loading mode referenced here by Mauricio.

Community
  • 1
  • 1
Berryl
  • 12,471
  • 22
  • 98
  • 182
0

I had the same problem, and found little or no help on all the forum and blog posts.

Note that this problem is specific to a case respecting all of the following criteria: - using SQLite - with System.Data.SqlLite - on an x64 machine - and NHibernate (2.1.2.4 in my case)

That chunk of config in my web.config (or app.config for my unit tests) got it to work. I had to qualify the assembly to be sure he loads 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 in it's inner plumbing, during the mapping using scanned assemblies, NHibernate creates an Assembly object using it's paritla name, as a string, "System.Data.SQLite". Somehow, the x86 version of the assembly got loaded.

The above configuration made sure that using the partial name to load an assembly would provide the x64 version.

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

Julien Bérubé
  • 1,256
  • 1
  • 13
  • 22
  • You are right about the problem criteria, I'm sure. Just to be clear, are you saying that this fix is *all* you need (no legacy runtime, target build settings, etc)? Also, does AMD64 cover any 64x processor or you have to look that up somewhere (where?)? Nice work tho - Cheers – Berryl Dec 18 '10 at 18:51
  • @Berryl. I can't test this right now as I don't have access to an Intel 64 machine, but I would guess you need to put IA64 in case of Intel 64 bits processors.Take a look at the enum System.Reflection.ProcessorArchitecture . – Julien Bérubé Dec 21 '10 at 17:21