FluentNhib + System.Data.SQLLite VS2010
I know this question has been posted here before, and I've trawled through as many answers as I could find, but I still can't get the simplest test in the world working.
1) I created my test and ensured it was working in in VS2008 and then opened the the solution in VS2010 (so it's all definlaty working, and all 3.5 code with all the assembly references 2.0/3.0/3.5 references)
2) I added the following config
<runtime>
<loadFromRemoteSources enabled="true"/>
<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>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
3) I tried the test against both the 1.0.60.0 x86 and 1.0.66.0 x64 SqlLite dlls
4) I tried running the tests in x86 and x64 modes
Still not passing. What have I missed?
(oh, and i'm using SQLite20Driver, and Copy Local is set to true)
The test is a simple Configure()
var cfg = Fluently.Configure(new NHibernate.Cfg.Configuration().Configure())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>()
.Conventions.AddFromAssemblyOf<RequiredPropertyConvention>())
.BuildConfiguration();
var sessionFactory = cfg.BuildSessionFactory();
Error
NHibernate.HibernateException: "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."
Stack Trace
at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, 开发者_运维知识库String commandTypeName)
at NHibernate.Driver.SQLite20Driver..ctor()
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type)
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings)
at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties)
at NHibernate.Cfg.Configuration.BuildSettings()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
NHibernate Config
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>
<property name="connection.connection_string">Data Source=nhibernate.db;Version=3</property>
<property name="dialect">NHibernate.Dialect.SQLiteDialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="query.substitutions">true=1, false=0</property>
</session-factory>
</hibernate-configuration>
If you’re migrating a VS2008 project to 2010, or even starting off a new project chances are that your project references a 3rd party assembly that has not yet been compiled against the .NET 4 framework (yet). To get a V2.0 assembly to run in the .Net 4 runtime you need to enable Mixed Mode, by adding the following to your web.config/app.config:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
useLegacyV2RuntimeActivationPolicy: This tells the runtime to bind assemblies built against older version of .NET against the V4 runtime instead of the runtimes they were built with (force them to use V4)
supportedRuntime: Letting .NEt know that your application supports the V4 runtime and to load your application in the V4 runtime.
For UnitTesting, adding this to the app.config of the project containing the TestFixtures isn’t enough. You need to add this to the app.config of the application actually running the tests, so for NUnit GUI you need to add it to the nunit.exe.config. Furthermore, you’ll need to ensure that you’re using a 2.5.3+ version of NUnit.
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime version="v4.0" />
<supportedRuntime version="v4.0"/>
</startup>
<runtime>
<loadFromRemoteSources enabled="true" />
</runtime>
</configuration>
loadFromRemoteSources: CAS has been deprecated in .Net 4 and this line forces partial trust V2 assemblies to be run in full trust.
requiredRuntime: This is because NUnit was built against V2 of the runtime, to load in V4 it needs to be told that it must run in the V4 runtime. (as opposed to only ‘supporting’ it)
If you using a different test runner, such as ReSharper’s test runner, TestDriven.Net or DXCore’s test runner you will need to ensure that you’ve changed their app.config’s to match the above (or wait for .Net 4 builds of them to be released)
Finally, if you’re using 3rd party assemblies that were compiled to target x86 specifically (this will mostly be assemblies that wrap other C/C++ assemblies, like System.Data.SQLite), you either need to grab the 64bit versions of them (as VS2010 by default compiles to x64 when using Any CPU as the Target) or change your Target to x86.
精彩评论