我正在使用最新的NHibernate 2.1.0Beta2。我正在尝试使用SQLite进行单元测试,并将配置设置为:
Dictionary<string, string> properties = new Dictionary<string, string>();
properties.Add("connection.driver_class", "NHibernate.Driver.SQLite20Driver");
properties.Add("dialect", "NHibernate.Dialect.SQLiteDialect");
properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
properties.Add("query.substitutions", "true=1;false=0");
properties.Add("connection.connection_string", "Data Source=test.db;Version=3;New=True;");
properties.Add("proxyfactory.factory_class",
"NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");
configuration = new Configuration();
configuration.SetProperties(properties);
当我尝试运行它时,我收到以下错误:
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 <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName) in c:\CSharp\NH\nhibernate\src\NHibernate\Driver\ReflectionBasedDriver.cs: line 26
at NHibernate.Driver.SQLite20Driver..ctor() in c:\CSharp\NH\nhibernate\src\NHibernate\Driver\SQLite20Driver.cs: line 28
所以看起来我需要直接引用程序集。我该怎么做才能让我不再犯这个错误?
我从这里下载了最新的程序集:http://sourceforge.net/projects/sqlite-dotnet2。
答案 0 :(得分:12)
您运行的是64位Windows吗?
浏览Google时,我看到几篇帖子评论SQLite dll文件是为x86而不是x64构建的。
请参阅此帖子:http://codetripper.wordpress.com/2009/01/03/using-sqlite-on-vista-64-bit/
编辑:我不知道截止时间,但我今天注意到System.Data.SQLite
的最新版本包含了x64 dll。 x64 .dll位于\bin\x64
。
答案 1 :(得分:6)
在添加对System.Data.SQLite程序集的引用之后,我不得不将copy local设置为true(在VS中选择程序集引用并转到属性),以便将程序集复制到bin目录。
答案 2 :(得分:3)
如果您不想使用64位版本的System.Data.Sqlite 您可以将“平台目标”(在visual studio project-&gt; properties-&gt; Build中)更改为x86。
答案 3 :(得分:3)
我遇到了同样的问题,而上述解决方案对我来说并不奏效。我认为System.Data.SQLite自那以后发生了变化。
请注意,此问题特定于尊重以下条件的所有的情况:
我的web.config(或我的单元测试的app.config)中的那一块配置让它运行起来。我必须对装配进行鉴定才能确保装载正确。
<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>
在内部管道的某处,在使用扫描程序集进行映射期间,NHibernate使用它的部分名称创建一个Assembly对象,作为字符串“System.Data.SQLite”。不知何故,装配的x86版本已加载。
上述配置确保使用部分名称加载程序集将提供x64版本。