简体   繁体   English

sqlite.net PCL抛出TypeInitalizationException

[英]sqlite.net PCL throws TypeInitalizationException

We changed from sqlite-net to sqlite.net PCL edition. 我们从sqlite-net更改为sqlite.net PCL版。 Our project worked fine with the old one - with the PCL edition, we now have to explicitely declare our platform by using. 我们的项目与旧项目合作得很好 - 在PCL版本中,我们现在必须通过使用明确声明我们的平台。

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

But now, when I call this line, we get a 但是现在,当我打电话给这一行时,我们得到一个

A first chance exception of type 'System.TypeInitializationException' occurred in SQLite.Net.Platform.Win32.dll SQLite.Net.Platform.Win32.dll中出现'System.TypeInitializationException'类型的第一次机会异常

Additional information: The type initializer for "SQLite.Net.Platform.Win32.SQLiteApiWin32Internal" threw an exception. 附加信息:“SQLite.Net.Platform.Win32.SQLiteApiWin32Internal”的类型初始化程序引发了异常。

The inner Exception tells us 内在的例外告诉我们

{"Failed to load native sqlite library"} {“无法加载本机sqlite库”}

Stacktrace: 堆栈跟踪:

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

at SQLite.Net.Platform.Win32.SQLiteApiWin32.Open(Byte[] filename, IDbHandle& db, Int32 flags, IntPtr zvfs) 在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) 在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) 在SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform,String databasePath,Boolean storeDateTimeAsTicks,IBlobSerializer serializer,IDictionary 2 tableMappings, IDictionary 2 extraTypeMappings,IContractResolver resolver)

However the sqlite3.dll is in the application folder and it actually did work with the unforked version. 但是,sqlite3.dll位于应用程序文件夹中,它实际上可以使用unforked版本。 I played around with compiling for x86 and x64 and downloaded the latest sqlite3.dll for Win32 but all without success. 我玩了编译x86和x64,并为Win32下载了最新的sqlite3.dll,但都没有成功。 What are we missing? 我们缺少什么?

I had the same problem in a tests project. 我在测试项目中遇到了同样的问题。 Solved it by adding the package http://www.nuget.org/packages/System.Data.SQLite.Core for the SQLitePlatformWin32. 通过为SQLitePlatformWin32添加包http://www.nuget.org/packages/System.Data.SQLite.Core解决了这个问题。

Although not listed as a dependency in the actual version, it was in previous one of the platform's nuget package ( http://www.nuget.org/packages/SQLite.Net.Platform.Win32/ ) 虽然未在实际版本中列为依赖项,但它是在平台的nuget包之前的一个( http://www.nuget.org/packages/SQLite.Net.Platform.Win32/

Additionally: in case of using SQLitePlatformGeneric a copy of sqlite3.dll should be placed in the output directory. 另外:如果使用SQLitePlatformGeneric,应将sqlite3.dll的副本放在输出目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM