C# 无法从NHibernate.driver.SQLite20Driver创建驱动程序

C# 无法从NHibernate.driver.SQLite20Driver创建驱动程序,c#,nhibernate,sqlite,C#,Nhibernate,Sqlite,下面是引发异常的代码 public Configuration GetConfiguration() { var persister = SQLiteConfiguration .Standard .UsingFile("Test.db") .ShowSql(); var configuration = Fluently .Configure()

下面是引发异常的代码

   public Configuration GetConfiguration()
    {
        var persister = SQLiteConfiguration
            .Standard
            .UsingFile("Test.db")
            .ShowSql();


        var configuration = Fluently
            .Configure()
            .Database(persister)
            .Mappings(map => map.FluentMappings.AddFromAssemblyOf<WordMap>())
            .BuildConfiguration();

        new SchemaExport(configuration).Execute(true, true, false);

        return configuration;

    }
公共配置GetConfiguration()
{
var persister=SQLiteConfiguration
标准
.UsingFile(“Test.db”)
.ShowSql();
变量配置=流畅
.Configure()
.数据库(持久化器)
.Mappings(map=>map.FluentMappings.AddFromAssemblyOf())
.BuildConfiguration();
新建SchemaExport(配置).Execute(真、真、假);
返回配置;
}
全文如下:

失败:NHibernate.HibernateException:无法创建驱动程序 来自NHibernate.Driver.SQLite20Driver,NHibernate,版本=2.1.2.4000, 区域性=中性,PublicKeyToken=aa95f207798dfdb4

---->System.Reflection.TargetInvocationException:调用的目标已引发异常

---->NHibernate.HibernateException:assembly System.Data.SQLite中的IDbCommand和IDbConnection实现可能失败 找不到。确保已找到程序集System.Data.SQLite 在应用程序目录或全局程序集缓存中。如果 程序集位于GAC中,请使用 应用程序配置文件,以指定 大会

NHibernate的版本是2.1.2.4000
System.Data.SQLite的版本为1.0.66.0
目标框架是3.5(x86)
System.Data.SQLite的本地副本已打开


可能有什么问题?

如果LocalCopy处于启用状态,则启动项目中的System.Data.SQLite版本是否处于启用状态,因为它将在启动项目中查找它,而不是在子项目的bin目录中。

我通过将useLegacyV2RuntimeActivationPolicy=“true”添加到app.config来解决此问题。请参见

无法从NHibernate.driver.SQLite20Driver创建驱动程序,NHibernate,版本=2.1.2.4000,区域性=中性,PublicKeyToken=aa95f207798dfdb4

解决方案:

测试设置: 选择主持人 选择在64位计算机上的64位进程中运行测试

希望我能帮忙


merry coding

只需将System.Data.SQLite.dll库复制到应用程序的基本目录(尤其是放置NHibernate.dll库的位置)。 您甚至不需要将其添加为VS下的引用

问候

Bronek

我刚刚安装了SQLite NuGet软件包,这对我来说很有效。

在VS2019年,在任何CPU项目的处理器架构中,我从x64改为了自动,解决了我的问题。

你看过安装System.Data.SQLite NuGet软件包吗,它是:安装System.Data.SQLite.Core包,它添加了System.Data.SQLite引用,这也使它能够工作。(也就是说,你不需要System.Data.SQLite包附带的所有其他东西,比如EF6支持。)