Sqlite.net PCL throws a TypeInitalizationException

We have changed from sqlite-net to sqlite.net PCL. Our project worked perfectly with the old one - with the release of PCL, now we must explicitly declare our platform using.

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

But now, when I call this line, we get

SQLite.Net.Platform.Win32.dll introduces the first exception of type exception "System.TypeInitializationException"

Additional information: the type initializer for "SQLite.Net.Platform.Win32.SQLiteApiWin32Internal" made an exception.

Inner exception tells us

{"Failed to load native sqlite library"}

Stacktrace:

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

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

in SQLite.Net.SQLiteConnection..ctor (ISQLitePlatform sqlitePlatform, String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks, follower for IBlobSerializer, IDictionary 2 tableMappings, IDictionary 2 extraTypeMappings, IContractResolver recognizer)

on SQLite.Net.SQLiteConnection..ctor (ISQLitePlatform sqlitePlatform, String databasePath, Boolean storeDateTimeAsTicks, follower for IBlobSerializer, IDictionary 2 tableMappings, IDictionary 2 extraTypeMappings, IContractResolver recognizer)

However, sqlite3.dll is located in the application folder and actually works with a non-circular version. I played with compilation for x86 and x64 and downloaded the latest version of sqlite3.dll for Win32, but all without success. What are we missing?

+5
source share
1 answer

I had the same problem in a test design. Solved it by adding the http://www.nuget.org/packages/System.Data.SQLite.Core package for SQLitePlatformWin32.

Although it is not listed as a dependency in the real version, it was in the previous package of the nuget platform ( http://www.nuget.org/packages/SQLite.Net.Platform.Win32/ )

Optional: if using SQLitePlatformGeneric, a copy of sqlite3.dll should be placed in the output directory.

+17
source

All Articles