DotNetCorePlugins: Unable to load e_sqlite3.dll for Microsoft.EntityFrameworkCore.Sqlite 3.0.0

Describe the bug DllNotFoundException thrown when using a plugin that consumes Microsoft.EntityFrameworkCore.Sqlite 3.0.0 . If I downgrade EFCore.Sqlite to 2.2.6, the plugin works fine.

System.TypeInitializationException: 'The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.'
DllNotFoundException: Unable to load DLL 'e_sqlite3' or one of its dependencies: The specified module could not be found. (0x8007007E)

To Reproduce Steps to reproduce the behavior: Version: 0.3.1 Code (In the main program):

public Assembly Load(string assemblyName)
{
    return PluginLoader.CreateFromAssemblyFile(assemblyName).LoadDefaultAssembly();
}

The plugin connects to a Sqlite3 database with Microsoft.EntityFrameworkCore.Sqlite 3.0.0 and print data to Console. (See the screenshot for details)

Expected behavior The plugin should not throw DllNotFoundException.

Screenshots image

Additional context

If I copy “e_sqlite3.dll” from “plugins\runtimes\win-x64\native\e_sqlite3.dll” to the “plugins” directory, the plugin won’t throw DllNotFoundException.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Sorry, but I don’t think there is anything I can do to fix this error. Under the hood, EF Core’s SQLite provider uses https://github.com/ericsink/SQLitePCL.raw. The way SQLitePCLRaw.nativelibrary is attempting to load the “e_sqlite3.dll” library circumvents this essential callback in System.Runtime.Loader.AssemblyLoadContext.

The root cause appears to be the use of System.Runtime.InteropServices.NativeLibrary. This doesn’t account for the current AssemblyLoadContext or the runtimes/$rid/native/*.dll layout. System.Runtime.Loader.AssemblyDependencyResolver might be a better library for SQLitePCLRaw to use, but I’ll leave that up to @ericsink.

Workaround

Change your plugin deployment to include a runtime identifier. dotnet publish --runtime win-x64 should do the trick.

Hi guys,

I was also facing the same issue. I found the solution and it’s working perfectly for me. If you ask I can write a detail note on the solution.

Hi! @jeremybytes have a blog post about this error here. Maybe his solution will ever help someone, although it’s a “work-around”.

I found its solution and it worked for me.

Solution:

First, I Removed all possible SQLite NuGet packages and then installed only one library(Nuget package) i.e “sqlite-net-pcl”( There are a number of different SQLite packages available – be sure to choose the correct one, it might not be the top result in search.) in all relevant project. It will download all its dependent packages. Please see below screenshot:

sqlite-net-pcl

Background:

There are two visual studio solutions; one is for Android and the other one is for iOS, and there are three projects in every solution. Two projects(used as libraries) are common for android and iOS solutions. In one common project, There is some SQLite code to handle database operations. So in this project, I installed the “sqlite-net-pcl” Nuget Package to fulfill the compile-time dependency.

Root cause analysis:

When I run the app, I found there is run time exception(Library e_sqlite3 not found. I concluded that the SQLite library is needed at run time in the Android project. So I added the same “sqlite-net-pcl” Nuget Package in the Android project as well. This package downloads all its relevant dependent packages. And this worked perfectly for me.

I hope it should work for everyone.

Thank you for your patience to read the entire solution.