【问题标题】:sqlite.net PCL throws TypeInitalizationExceptionsqlite.net PCL 抛出 TypeInitalizationException
【发布时间】:2015-08-04 14:55:49
【问题描述】:

我们从 sqlite-net 更改为 sqlite.net PCL 版本。我们的项目在旧版本上运行良好 - 在 PCL 版本中,我们现在必须通过 using 明确声明我们的平台。

var conn = new SQLiteConnection(new SQLitePlatformWin32(),  Path.Combine(folderPath, dbName));

但是现在,当我调用这条线时,我们得到一个

在 SQLite.Net.Platform.Win32.dll 中发生了“System.TypeInitializationException”类型的第一次机会异常

附加信息:“SQLite.Net.Platform.Win32.SQLiteApiWin32Internal”的类型初始化程序引发异常。

内部异常告诉我们

{"加载原生 sqlite 库失败"}

堆栈跟踪:

在 SQLite.Net.Platform.Win32.SQLiteApiWin32Internal.sqlite3_open_v2(Byte[] filename, IntPtr& db, Int32 flags, IntPtr zvfs)

在 SQLite.Net.Platform.Win32.SQLiteApiWin32.Open(Byte[] filename, IDbHandle& db, Int32 flags, IntPtr zvfs)

在 SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform, String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks, IBlobSerializer 序列化器, IDictionary2 tableMappings, IDictionary2 extraTypeMappings, IContractResolver 解析器)

在 SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform, String databasePath, Boolean storeDateTimeAsTicks, IBlobSerializer 序列化器, IDictionary2 tableMappings, IDictionary2 extraTypeMappings, IContractResolver 解析器)

但是 sqlite3.dll 位于应用程序文件夹中,并且它确实适用于未分叉的版本。我尝试为 x86 和 x64 进行编译,并为 Win32 下载了最新的 sqlite3.dll,但都没有成功。我们缺少什么?

【问题讨论】:

    标签: c# sqlite sqlite-net


    【解决方案1】:

    我在测试项目中遇到了同样的问题。 通过为 SQLitePlatformWin32 添加包 http://www.nuget.org/packages/System.Data.SQLite.Core 解决了这个问题。

    虽然在实际版本中没有列为依赖项,但它在平台的前一个 nuget 包中(http://www.nuget.org/packages/SQLite.Net.Platform.Win32/

    另外:如果使用 SQLitePlatformGeneric,则应将 sqlite3.dll 的副本放在输出目录中。

    【讨论】:

    • 这就是解决方案 - 缺少互操作 dll 文件,在将核心包添加到我的项目后,它还添加了这些文件。有趣的是,我不必将文件作为直接依赖项添加到我的类库项目(我有 sqlite pcl 文件)中,而是添加到我的 gui 项目中,该项目依赖于类库以使其工作。
    • 确保选择正确的 .Core 包 (x86/x64),而不是 MSIL .Core 包。
    • SQLitePlatformWin32和SQLitePlatformGeneric有什么区别?
    • @batmaci 来自平台 git repo 上的自述文件 github.com/oysteinkrog/SQLite.Net-PCL#sqliteconnection "Win32(为 windows 捆绑 sqlite 二进制文件,自动在 x86 和 x64 上工作)" "通用(没有任何 sqlite3 二进制文件的 net4 项目,需要安装在操作系统中的sqlite)"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 2018-11-23
    • 1970-01-01
    • 2014-11-25
    • 2015-12-15
    • 1970-01-01
    相关资源
    最近更新 更多