Microsoft.Data.SQLite: Library e_sqlite3 not found

Viewed 8587

Problem: I'm trying to develop an ASP.NET MVC (.Net Framework 4.7.2) web app in which I want to use Microsoft.Data.Sqlite version (5.0.2), but when I run it my web app crashes (both in debug IIS Express, and in app.publish on local IIS on Windows 10) at following code line:

SqliteConnection dbConn = new SqliteConnection("Data Source=test.db");

The exception thrown is as under:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
  Source=Microsoft.Data.Sqlite
  StackTrace:
   at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
   at sqliteTest.Controllers.ValuesController.Get() in C:\Users\FaqeerHussain\source\repos\sqliteTest\sqliteTest\Controllers\ValuesController.cs:line 16
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 2:
Exception: Library e_sqlite3 not found

What I've tried so far: Following Inner Exception: Library e_sqlite3 not found tried looking around the 'bin' folder, and found that e_sqlite3.dll is already there in bin\runtimes\win-x64\native and also in bin\runtimes\win-x86\native folders, both contain e_sqlite3.dll. Tried copying manually the above-mentioned x86/x64 e_sqlite3.dll to root bin folder but the error still remains.

What should I do to get Microsoft.Data.Sqlite working in my ASP.NET MVC (.NET Framework 4.7.2) web app?

6 Answers

This is because the package of Microsoft.Data.Sqlite is not compatible with the version of .Net Framework. You can try to change the version of NuGet of Microsoft.Data.Sqlite to 2.2.0 to run normally.

enter image description here

I found that the e_sqlite3.dll is located at runtimes\win-x86\native\e_sqlite3.dll. So I created those folders and added the e_sqlite3.dll in the native folder. After that it worked!

For anyone else running into this issue, unfortunately it's a known issue that hasn't been fixed yet.

In my case I was referencing a .NET Standard 2.0 library that was using Sqlite, from a .NET Framework 4.8 project. I simply changed the library to also target .NET 4.8 as a workaround since it wasn't being used by any other implementation of .NET.

So I had to change <TargetFramework>netstandard2.0</TargetFramework> to <TargetFramework>net48</TargetFramework> in my Sqlite project.

I have also working on to develop an ASP.NET (.Net Framework 4.7) web app in which I have used Microsoft.Data.Sqlite version (5.0.10), but when I run it my web app, it crashes and give me Exception: Library e_sqlite3 not found

I have almost take one and half day to solved this problem. In my case, I have remove dependency library of 'Microsoft.Data.Sqlite' and others such as Microsoft.Data.Sqlite.Core, SQLitePCLRaw.bundle_e_sqlite3, SQLitePCLRaw.core, SQLitePCLRaw.lib.e_sqlite3, SQLitePCLRaw.provider.dynamic_cdecl, etc. from package folder.

Now, I have added new Microsoft.Data.Sqlite with version (6.0.0) along with its dependencies. My app is working fine. (Note: I have only used this library to read SpatiaLite database and to call SpatiaLite function.)

Dump Microsoft.Data.Sqlite in favor of System.Data.Sqlite. It supports version 3.38 databases with upserts an other perks and has no such issues. I did and never looked back.

The difference will be in the casing of the names:

using System.Data.SQLite;

Instead of:

SqliteConnectionStringBuilder
SqliteConnection
SqliteCommand
SqliteTransaction
SqliteType.Text

you will use, respectively:

SQLiteConnectionStringBuilder
SQLiteConnection
SQLiteCommand
SQLiteTransaction
DbType.String etc

I had to go all the way back to the version of Microsoft.Data.Sqlite that used to work for my older projects (4.7.2 and pre): to 1.0.0. One would think that while making 72 more releases the developer should notice the problem, but no, this is too much to ask for. And I did check: the platform subfolders and DLLs were there. From one DLL hell into another!

Related