Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

.net - Problems using FluentNHibernate + SQLite with .NET4?

I have a WPF application running with VS2010 .Net3.5 using Nhibernate with FluentNHibernate + SQLite, and all works fine.

Now I want to change to use .Net4, but this has turned into a more painful experience then I expected.. When setting up the connection I do this:

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

The BuildSessionFactory() call throws a FluentConfigurationException saying:

An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more details.

The inner exception gives us more information:

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

And further 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.

Notes:

  • This is exactly the same code that worked just fine before I upgraded to .Net4.
  • I did see some x64 x86 mismatch problems earlier, but I have switched to use x86 as the target platform and for all referenced dlls. I have verified that all files in the Debug-folder are x86.
  • I have tried the precompiled Fluent dlls, I have tried compiling myself, and I have compiled my own version of Fluent using .Net4.
  • I see that there are also others that have seen this problem, but I haven't really seen any solution yet.

After @devio's answer I tried adding a reference to the SQLite dll. This didn't change anything, but I hope I made it right though.. This is what I added to the root node of the app.config file:

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

Anyone out there using Fluent with .Net4 and SQLite successfully? Help! I'm lost...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I also got the same error message when I tried Fluent with .Net4 and SQLite, but when I looked more closely, I found different error message.

Could not load type System.Data.SQLite.SQLiteConnection, System.Data.SQLite. System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

So what I did is to add useLegacyV2RuntimeActivationPolicy="true" to the "startup" tag like this.

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

I don't need to add dependentAssembly or anything inside the "runtime" tag. According to this link text and this link text, it should be used for migration aid only. So hopefully, SQLite will be updated soon.

Hope this helps! Karlkim


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...