Search code examples
c#sqliteentity-framework-coremacos-mojavesystem.data.sqlite

SQLitePCLRaw on macOS Mojave : Unable to load shared library 'e_sqlite3' or one of its dependencies


I have a C# cross platform (Windows + macOS) app that uses EF Core with SQLite to access a local database that is shipped with the app.

It works perfectly on all Windows devices and on the recent versions of macOS. However one of my user has a problem on his macOS Mojave (10.14). The first time the app try to access the database (no matter the operation: read, write, migration, etc), the following exception is raised:

System.DllNotFoundException: Unable to load shared library 'e_sqlite3' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libe_sqlite3, 1): image not found at SQLitePCL.SQLite3Provider_e_sqlite3.NativeMethods.sqlite3_libversion_number() at SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number() at SQLitePCL.raw.SetProvider(ISQLite3Provider imp) at SQLitePCL.Batteries_V2.Init()

Here are my nuget packages for info: enter image description here

What I tried:

  • I tried to replace the SQLitePCLRaw.bundle nuget package by other bundle, without any success. I also updated the bundle to the 2.1.6 version which came out a few days ago, still no success
  • I had my user run the command "sqlite3" in terminal and it looks like SQLite3 is correctly installed on his device (SQLite version 3.24.0)
  • I tried to reproduce the bug on a few Mac I have access to, but it works correctly each time. Note that these Mac are all M1 or M2, so I guess the problem only occurs on older version

I'm having a hard time figuring out what's causing this and would appreciate any help.

Thanks


Solution

  • I had the same problem, and it appears to be related to the Microsoft.EntityFrameworkCore.SQLite NuGet package. The latest version that works on macOS Mojave (10.14) is 7.0.2, every version after that the dynamic library doesn't load. Not sure if compatibility could be restored in later versions, but since Mojave is quite outdated I doubt that compatibility will be restored in newer versions. So if it really needs to work on Mojave you probably have to stick with the 7.0.2 version of this package.