Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft.Data.SQLite: Library e_sqlite3 not found

My ASP.NET MVC (.Net Framework 4.7.2) web app using Microsoft.Data.Sqlite 5.0.2 crashes (both in debug IIS Express, and app.publish on local IIS in Windows 10) at line:

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

The exception thrown :

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

e_sqlite3.dll is already in bin\runtimes\win-x64\native and bin\runtimes\win-x86\native. Tried copying x86/x64 e_sqlite3.dll to root bin folder but error remains. What should I do to get Microsoft.Data.Sqlite working?

like image 911
FAQi Avatar asked Sep 10 '25 19:09

FAQi


2 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

like image 126
samwu Avatar answered Sep 13 '25 08:09

samwu


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!

Edit: Create folder at: C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\runtimes\win-x64\native (match your vs version).

Copy from: C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions and search the e_sqlite3.dll because the folder name can be different.

like image 23
Paul Albers Avatar answered Sep 13 '25 09:09

Paul Albers