Problems using FluentNHibernate + SQLite with .NET4? Problems using FluentNHibernate + SQLite with .NET4? sqlite sqlite

Problems using FluentNHibernate + SQLite with .NET4?


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


Check the version of your System.Data reference. It sounds to me like System.Data.SqlLite can't find the version of IDbCommand and IDbConnection that it was built with which I suspect is version 2.0.0.0. I suspect that now you've upgraded to .Net 4 you are referencing System.Data version 4.0.0.0.

If this is the case you should be able to add a binding redirect to resolve the problem:

<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>


I had a similar problem with NH, VS2010, .Net4, but with the Oracle ODP.Net drivers and 32bit.

The solution was to declare a "qualified assembly" in the web.config file with an explicit version number. See my summary.

Maybe this solution applies to your problem as well.