Unit testing 如何将SQLite配置为与NHibernate一起运行,其中程序集解析System.Data.SQLite?

Unit testing 如何将SQLite配置为与NHibernate一起运行,其中程序集解析System.Data.SQLite?,unit-testing,nhibernate,sqlite,Unit Testing,Nhibernate,Sqlite,我正在使用最新的NHibernate 2.1.0Beta2。我正在尝试使用SQLite进行单元测试,并将配置设置为: Dictionary<string, string> properties = new Dictionary<string, string>(); properties.Add("connection.driver_class", "NHibernate.Driver.SQLite20Driver"); pr

我正在使用最新的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);
字典属性=新建字典();
添加(“connection.driver_class”,“NHibernate.driver.SQLite20Driver”);
添加(“方言”、“NHibernate.dialogue.sqlitedialogue”);
添加(“connection.provider”、“NHibernate.connection.DriverConnectionProvider”);
properties.Add(“query.substitutions”,“true=1;false=0”);
添加(“connection.connection\u string”,“数据源=test.db;版本=3;新=True;”;
添加(“proxyfactory.factory\u类”,
“NHibernate.ByteCode.LinFu.proxyFactory,NHibernate.ByteCode.LinFu”);
配置=新配置();
配置.SetProperties(属性);
当我尝试运行它时,出现以下错误:

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 
NHibernate.HibernateException:在程序集System.Data.SQLite中找不到IDbCommand和IDbConnection实现。确保程序集System.Data.SQLite位于应用程序目录或全局程序集缓存中。如果程序集位于GAC中,请使用应用程序配置文件中的元素指定程序集的全名。
在c:\CSharp\NH\NHibernate\src\NHibernate\Driver\ReflectionBasedDriver..ctor(字符串驱动程序RassemblyName、字符串连接类型名称、字符串命令类型名称)中的NHibernate.Driver.ReflectionBasedDriver..ctor处:第26行
在c:\CSharp\NH\NHibernate\src\NHibernate\Driver\SQLite20Driver.cs中的NHibernate.Driver.SQLite20Driver..ctor()处:第28行
看起来我需要直接引用程序集。我该如何做才能不再出现这个错误


我从这里下载了最新的程序集:。

您正在运行64位Windows吗

环顾谷歌,我看到一些帖子评论说SQLite dll文件是为x86而不是x64构建的

见此帖:

Edit:我不确定何时发布,但我今天注意到
System.Data.SQLite
的最新版本包括x64 dll。dll位于
\bin\x64


在添加对System.Data.SQLite程序集的引用后,我必须将copy local设置为true(在VS中选择程序集引用并转到属性),以便将程序集复制到bin目录。

如果您不想使用64位版本的System.Data.SQLite
您可以将“平台目标”(在visual studio project->properties->Build中)更改为x86。

我也遇到了同样的问题,上面的解决方案对我来说不起作用。我认为System.Data.SQLite自那以后发生了变化

请注意,此问题仅适用于符合以下所有标准的情况:

  • 使用SQLite
  • 使用System.Data.SqlLite
  • 在x64机器上
  • 和NHibernate(在我的案例中为2.1.2.4)
我的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在其内部管道的某个位置使用它的部分名称创建一个程序集对象,作为字符串“System.Data.SQLite”。不知怎的,程序集的x86版本被加载了


上述配置确保了使用部分名称加载程序集将提供x64版本。

。感谢您的帮助。您始终可以将单元测试项目设置为编译为x86(在项目属性中的“构建”选项卡),如果项目在不全部使用64位windows的开发人员之间共享,我必须这样做。sqlite-dotnet2中的代码是否在应用程序目录中?(或在GAC注册?)我在我的项目参考资料中有对System.Data.SQLite.DLL的参考。我假设当我运行单元测试(通过Resharper单元测试运行程序)时,它会将它复制过来。如果有人遇到这个问题并正在寻找这个答案的更新版本-
我博客中关于这个问题的帖子比这里的答案更新得多…