sqlite.net PCL抛出TypeInitalizationException

Mar*_*wie 6 c# sqlite sqlite-net

我们从sqlite-net更改为sqlite.net PCL版.我们的项目与旧项目合作得很好 - 在PCL版本中,我们现在必须通过使用明确声明我们的平台.

var conn = new SQLiteConnection(new SQLitePlatformWin32(),  Path.Combine(folderPath, dbName));
Run Code Online (Sandbox Code Playgroud)

但是现在,当我打电话给这一行时,我们得到一个

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标志,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序列化程序,IDictionary 2 tableMappings, IDictionary2 extraTypeMappings,IContractResolver解析器)

在SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform,String databasePath,Boolean storeDateTimeAsTicks,IBlobSerializer serializer,IDictionary 2 tableMappings, IDictionary2 extraTypeMappings,IContractResolver resolver)

但是,sqlite3.dll位于应用程序文件夹中,它实际上可以使用unforked版本.我玩了编译x86和x64,并为Win32下载了最新的sqlite3.dll但都没有成功.我们缺少什么?

小智 18

我在测试项目中遇到了同样的问题.通过为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 项目中,该项目依赖于类库来使其工作。 (2认同)