BradLaney
BradLaney

Reputation: 2413

Running NUnit against .Net 4.0 NHibernate over SQLite cannot load SQLite DLL

I know this is a "duplicate", but the answers on all the other posts are not working for me. My error message is also slightly different.

No matter what I try I cannot get SQLite to to run. I have tried every thing I could find on the net/stackoverflow and every set of SQLite DLLs.

I have tried:

<runtime>
    <loadFromRemoteSources enabled="true" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089"/>
            <bindingRedirect oldVersion="2.0.0.0" newVersion="4.0.0.0"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>

I also have tried both safe and unsafe versions of the DLLs. NUnit.exe will pass the test, but running them with TestDriven.Net in visual studio does not work.

Full stack trace when fluent nhibernate runs the configuration:

SetUp : FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
  ----> 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.
  d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs(232, 0) : FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
  C:\inetpub\wwwroot\TrunkB\Company.Tests\BaseNHibernateTest.cs(50, 0) : Company.Tests.BaseSQLiteNHibernateTest.<SetUp>b__1(IInitializationExpression x)
  C:\inetpub\wwwroot\TrunkB\Company.Tests\BaseNHibernateTest.cs(36, 0) : Company.Tests.BaseSQLiteNHibernateTest.SetUp()
  d:\CSharp\NH\NH\nhibernate\src\NHibernate\Dialect\Schema\AbstractDataBaseSchema.cs(97, 0) : NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetReservedWords()
  d:\CSharp\NH\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaMetadataUpdater.cs(47, 0) : NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
  d:\CSharp\NH\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaMetadataUpdater.cs(17, 0) : NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory)
  d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SessionFactoryImpl.cs(169, 0) : NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
  d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs(1246, 0) : NHibernate.Cfg.Configuration.BuildSessionFactory()
  d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs(227, 0) : FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()

I am also getting this error now:

Company.Tests.Infrastructure.TruckRepositoryTests.CanLoadTrucksByUserIdFilter:
SetUp : System.BadImageFormatException : Could not load file or assembly 'System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Upvotes: 1

Views: 2112

Answers (2)

majimenezp
majimenezp

Reputation: 312

I have this problem using fluent nhibernate and automappings with sqlite, in a .net framework 4 solution, i checked in the new system.data.sqlite site and it's a problem related with the resources inside the library, they already fixed but not it's not a release soon.

The link with the checkin: Checkin info in system.data.sqlite repository

I downloaded the source code i compiled myself, and it's working now with the automapper in fluent nhibernate, maybe can work for you meanwhile the people of system.data.sqlite relase a new version:

Compiled source code of 1.0.74.0 version with the fix

Upvotes: 3

Can Gencer
Can Gencer

Reputation: 8885

System.BadImageFormatException

This most likely means that you are trying to load a 32-bit assembly into a 64-bit process or vice versa. I imagine that you are running a 64-bit operating system. In this case the program will run as a 64-bit process if Any CPU configuration is selected. One of NUnit and Testdriven.NET might be running as 32-bit and the other 64-bit which will explain why one works and the other doesn't.

Make sure that you are using the correct version of Sqlite (32 bit or 64 bit) when running with a 32/64 bit process.

UPDATE: There is an option for TestDriven.NET for it use 32-bit or 64-bit processes. Go to Tools -> Options -> TestDriven.NET and change ANY CPU tests to use 64-bit instead.

Upvotes: 4

Related Questions