sqlite.net PCL 抛出 TypeInitalizationException
sqlite.net PCL throws TypeInitalizationException
我们从 sqlite-net 更改为 sqlite.net PCL 版本。我们的项目在旧版本上运行良好 - 使用 PCL 版本,我们现在必须通过使用明确声明我们的平台。
var conn = new SQLiteConnection(new SQLitePlatformWin32(), Path.Combine(folderPath, dbName));
但是现在,当我调用这一行时,我们得到一个
A first chance exception of type 'System.TypeInitializationException' occurred in SQLite.Net.Platform.Win32.dll
Additional information: The type initializer for "SQLite.Net.Platform.Win32.SQLiteApiWin32Internal" threw an exception.
内部异常告诉我们
{"Failed to load native sqlite library"}
堆栈跟踪:
at SQLite.Net.Platform.Win32.SQLiteApiWin32Internal.sqlite3_open_v2(Byte[] filename, IntPtr& db, Int32 flags, IntPtr zvfs)
at SQLite.Net.Platform.Win32.SQLiteApiWin32.Open(Byte[] filename, IDbHandle& db, Int32 flags, IntPtr zvfs)
at SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform, String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks, IBlobSerializer serializer, IDictionary2 tableMappings, IDictionary
2 extraTypeMappings, IContractResolver resolver)
at SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform, String databasePath, Boolean storeDateTimeAsTicks, IBlobSerializer serializer, IDictionary2 tableMappings, IDictionary
2 extraTypeMappings, IContractResolver resolver)
但是 sqlite3.dll 在应用程序文件夹中,它实际上可以与未分叉的版本一起使用。我试着为 x86 和 x64 编译,并为 Win32 下载了最新的 sqlite3.dll,但都没有成功。我们缺少什么?
我在测试项目中遇到了同样的问题。
通过为 SQLitePlatformWin32 添加包 http://www.nuget.org/packages/System.Data.SQLite.Core 来解决它。
虽然在实际版本中没有列为依赖项,但它在平台的前一个 nuget 包中(http://www.nuget.org/packages/SQLite.Net.Platform.Win32/)
另外:如果使用 SQLitePlatformGeneric,sqlite3.dll 的副本应该放在输出目录中。
我们从 sqlite-net 更改为 sqlite.net PCL 版本。我们的项目在旧版本上运行良好 - 使用 PCL 版本,我们现在必须通过使用明确声明我们的平台。
var conn = new SQLiteConnection(new SQLitePlatformWin32(), Path.Combine(folderPath, dbName));
但是现在,当我调用这一行时,我们得到一个
A first chance exception of type 'System.TypeInitializationException' occurred in SQLite.Net.Platform.Win32.dll
Additional information: The type initializer for "SQLite.Net.Platform.Win32.SQLiteApiWin32Internal" threw an exception.
内部异常告诉我们
{"Failed to load native sqlite library"}
堆栈跟踪:
at SQLite.Net.Platform.Win32.SQLiteApiWin32Internal.sqlite3_open_v2(Byte[] filename, IntPtr& db, Int32 flags, IntPtr zvfs)
at SQLite.Net.Platform.Win32.SQLiteApiWin32.Open(Byte[] filename, IDbHandle& db, Int32 flags, IntPtr zvfs)
at SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform, String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks, IBlobSerializer serializer, IDictionary
2 tableMappings, IDictionary
2 extraTypeMappings, IContractResolver resolver)at SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform, String databasePath, Boolean storeDateTimeAsTicks, IBlobSerializer serializer, IDictionary
2 tableMappings, IDictionary
2 extraTypeMappings, IContractResolver resolver)
但是 sqlite3.dll 在应用程序文件夹中,它实际上可以与未分叉的版本一起使用。我试着为 x86 和 x64 编译,并为 Win32 下载了最新的 sqlite3.dll,但都没有成功。我们缺少什么?
我在测试项目中遇到了同样的问题。 通过为 SQLitePlatformWin32 添加包 http://www.nuget.org/packages/System.Data.SQLite.Core 来解决它。
虽然在实际版本中没有列为依赖项,但它在平台的前一个 nuget 包中(http://www.nuget.org/packages/SQLite.Net.Platform.Win32/)
另外:如果使用 SQLitePlatformGeneric,sqlite3.dll 的副本应该放在输出目录中。