Library e_sqlite3 not found
I am getting the below exception in my .net application targeting to .net 4.7.2 and platform set as Any CPU. I have tried many things but couldn't succceed. Then I tried the exact same code and configuration of the official sample app which works fine for me when I set the target framework as .net 8. But it gives the same exception when I use the same code and configuration in a sample .net application.
https://github.com/dotnet/docs/tree/main/samples/snippets/standard/data/sqlite/HelloWorldSample
Library e_sqlite3 not found
plat: win
suffix: DLL
possibilities (3):
1) C:\work\ConsoleApp9\ConsoleApp9\bin\Debug\runtimes\win-x86\native\e_sqlite3.dll
2) C:\work\ConsoleApp9\ConsoleApp9\bin\Debug\e_sqlite3.dll
3) C:/work/ConsoleApp9/ConsoleApp9/bin/Debug/e_sqlite3.dll
win TryLoad: C:\work\ConsoleApp9\ConsoleApp9\bin\Debug\runtimes\win-x86\native\e_sqlite3.dll
thrown: System.ComponentModel.Win32Exception (0x80004005): The specified module could not be found
at SQLitePCL.NativeLibrary.TryLoad(String name, Loader plat, Action`1 log, IntPtr& h)
win TryLoad: C:\work\ConsoleApp9\ConsoleApp9\bin\Debug\e_sqlite3.dll
thrown: System.ComponentModel.Win32Exception (0x80004005): The specified module could not be found
at SQLitePCL.NativeLibrary.TryLoad(String name, Loader plat, Action`1 log, IntPtr& h)
win TryLoad: C:/work/ConsoleApp9/ConsoleApp9/bin/Debug/e_sqlite3.dll
thrown: System.ComponentModel.Win32Exception (0x80004005): The specified module could not be found
at SQLitePCL.NativeLibrary.TryLoad(String name, Loader plat, Action`1 log, IntPtr& h)
NOT FOUND
2 answers
-
Jack Dang (WICLOUD CORPORATION) 18,970 Reputation points • Microsoft External Staff • Moderator
Hi @Vivek Nuna ,
Thanks for reaching out.
The managed library used by Microsoft.Data.Sqlite relies on the native SQLite engine that is loaded through SQLitePCLRaw. If that native DLL isn’t present in the build output, the runtime throws the “Library e_sqlite3 not found” exception.
The reason your sample works when targeting .NET 8 but fails with .NET Framework 4.7.2 is that modern .NET handles native runtime assets automatically.
A couple of things you can check:
- Ensure the SQLite native bundle package is installed
Add the following NuGet package if it isn’t already referenced:
- SQLitePCLRaw.bundle_e_sqlite3
This package includes the
e_sqlite3.dllbinaries and ensures they are copied to your output directory.- Initialize the SQLite bundle (sometimes required in .NET Framework apps)
Add the initialization call early in your program (for example in
Main):SQLitePCL.Batteries.Init();- Verify the native library exists in the output folder
After building, check your
bin\Debug(orbin\Release) directory and confirm thate_sqlite3.dllor theruntimes\win-x86/nativeorruntimes\win-x64/nativefolders are present. If the DLL is missing, the runtime will fail to load SQLite.- Check platform architecture if needed
If your project is set to Any CPU, you may also try explicitly setting the platform target to x64 or x86 to match the available native runtime.
If you found my response helpful or informative in any way, I would greatly appreciate it if you could follow this guidance provide feedback. Thank you.
-
Jack Dang (WICLOUD CORPORATION) 18,970 Reputation points • Microsoft External Staff • Moderator
Hi @Vivek Nuna ,
Have you seen my answer in this post? If you have any question, feel free to reach out. I'm happy to support you.
Sign in to comment -
AI answer
The exception indicates that the native SQLite library
e_sqlite3.dll(from SQLitePCLRaw) is not being deployed for the .NET Framework 4.7.2 app, even though it works for .NET 8 with the same managed code. For .NET Framework, the correct bundle/provider packages must be referenced explicitly so that the native binaries are copied to the output folder.To fix this for a .NET 4.7.2 application:
- Remove
Microsoft.Data.Sqliteif it is bringing in a bundle that is not working correctly for the .NET Framework project. - Add
Microsoft.Data.Sqlite.Coreand an appropriate SQLitePCLRaw bundle (or provider) that includes the nativee_sqlite3library. For example, to use the defaulte_sqlite3bundle (recommended):
or via Package Manager Console:dotnet add package Microsoft.Data.Sqlite.Core dotnet add package SQLitePCLRaw.bundle_e_sqlite3
Bundles likeInstall-Package Microsoft.Data.Sqlite.Core Install-Package SQLitePCLRaw.bundle_e_sqlite3SQLitePCLRaw.bundle_e_sqlite3are automatically initialized byMicrosoft.Data.Sqliteand ensure the correct native binaries are present for each platform. - Clean and rebuild the project, then confirm that under
bin\Debug(orbin\Debug\<target>), aruntimes\win-x86\native\e_sqlite3.dllor equivalent path exists.
If instead of a bundle a specific provider is desired, install
SQLitePCLRaw.coreplus a provider package and configure it before usingMicrosoft.Data.Sqlite. For example, to use the system SQLite provider:dotnet add package Microsoft.Data.Sqlite.Core dotnet add package SQLitePCLRaw.core dotnet add package SQLitePCLRaw.provider.sqlite3Then set the provider at startup:
using Microsoft.Data.Sqlite; class Program { static void Main() { SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3()); using var connection = new SqliteConnection("Data Source=hello.db"); connection.Open(); } }This ensures that the correct native SQLite implementation is loaded instead of the missing
e_sqlite3.dll.
References:
AI-generated content may be incorrect. Read our transparency notes for more information. - Remove
