System.DllNotFoundException on Mono SQLite
Solution 1
Use Mono.Data.SQLite.dll
on Linux. Take a look at the Mono manual to using SQLite on Linux or build the System.Data.SQLite.dll on Mono.
You can also map the DLL:
<configuration>
<dllmap dll="sqlite" target="libsqlite.so.0" os="linux"/>
<dllmap dll="sqlite" target="libsqlite.0.dylib" os="osx"/>
<dllmap dll="sqlite3" target="libsqlite3.so.0" os="linux"/>
<dllmap dll="sqlite3" target="libsqlite3.0.dylib" os="osx"/>
</configuration>
Solution 2
No code changes necessary. You can build it yourself.
apt-get install build-essentials unzip
- Download the SQLITE source code - you want the full source code. Currently called sqlite-netFx-full-source-1.0.104.0.zip.
-
unzip
andcd Source
, -
chmod +x
thecompile-interop-assembly-release.sh
build shell script, then run it./compile-interop-assembly-release.sh
. - It'll build an.so
file in the../bin
directory. - Copy this
.so
file to the directory that has your application in - Run your application as normal.
- Note: Ensure that your SQLite database and the directory it's inside of are writable by the user you're trying to run as.
Solution 3
I started the development in Windows, but then moved the application to Mono (Ubuntu 14), which is where the SQLite provider failed to load as OP described.
I had to recompile the System.Data.SQLite.dll using the following command:
MSBuild System.Data.SQLite.2012.csproj /t:Rebuild /p:UseInteropDll=false /p:UseSqliteStandard=true
However, after this I've got the following exception:
The provider did not return a ProviderManifest instance. Method
System.Data.SQLite.UnsafeNativeMethods:GetSettingValue (string,string)' is inaccessible from method
System.Data.SQLite.EF6.SQLiteProviderManifest:GetProviderManifestToken (string)'
To fix this, I had to recompile the System.Data.SQLite.EF6.dll using the following command:
MSBuild System.Data.SQLite.EF6.2012.csproj /t:Rebuild /p:UseInteropDll=false /p:UseSqliteStandard=true
After copying all of the generated files to Mono project's bin directory, everything worked.
The SQLite provider source code version I had used was 1.0.98.1.
Hope this saves someone a lot of time...
Solution 4
I tried all the above option but those options could not solve SQLite DLL problem, It may be because I am using ubuntu 18 version, So tried other option and here the steps,
1) Download SQLite source code from the https://system.data.sqlite.org/downloads/1.0.111.0/sqlite-netFx-full-source-1.0.111.0.zip
2) unzip source code and cd to unzip directory
3) Run the following command in the terminal,
xbuild /p:Configuration=Release /p:UseInteropDll=false /p:UseSqliteStandard=true ./System.Data.SQLite/System.Data.SQLite.2010.csproj
4) Above command would create a dll file at following path,
sqlite-netFx-full-source-1.0.111.0/bin/2010/ReleaseMonoOnPosix/bin
5) Copy System.Data.SQLite.dll to your project bin folder.
6) Clean project and build again.
I hope this would help.
Solution 5
Starting with System.Data.SQLite.Core 1.0.109 you don't need to compile anything yourself since the native SQLite.Interop.dll
files are included in the NuGet package for all platforms (Linux, macOS and Windows). Note that although the dll
extension is used for all platforms, the files are actually native dynamic libraries (usually suffixed dylib on macOS and so on Linux).
$ find ~/.nuget/packages/system.data.sqlite.core/1.0.111/runtimes -name SQLite.Interop.dll -print0 | xargs -0 file
…/runtimes/linux-x64/native/netstandard2.0/SQLite.Interop.dll: ELF 64-bit LSB pie executable x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=96ce4120b31bad7d95f7b9ccf7c4bbb7717ae0b1, with debug_info, not stripped
…/runtimes/osx-x64/native/netstandard2.0/SQLite.Interop.dll: Mach-O 64-bit dynamically linked shared library x86_64
…/runtimes/win-x86/native/netstandard2.0/SQLite.Interop.dll: PE32 executable (DLL) (GUI) Intel 80386, for MS Windows
…/runtimes/win-x64/native/netstandard2.0/SQLite.Interop.dll: PE32+ executable (DLL) (GUI) x86-64, for MS Windows
Unfortunately, the MSBuild target responsible for copying the native dynamic libraries into the output directory only works on Windows. This is probably because the authors of the package assumed that .NET Framework only runs on Windows, which is not true thanks to Mono. Also, if you wanto to have a look, the CopySQLiteInteropFiles
target can be found in ~/.nuget/packages/system.data.sqlite.core/{version}/build/net4*/System.Data.SQLite.Core.targets
.
But it's possible to automatically copy the SQLite.Interop.dll
file into the output directory on Linux and macOS. Add the FixSQLiteInteropFilesOnLinuxAndOSX
target (described below) in your csproj file and you'll be able to use System.Data.SQLite.Core on Linux and macOS running mono without the DllNotFoundException
. Here's how your project should look like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
</PropertyGroup>
<Target Name="FixSQLiteInteropFilesOnLinuxAndOSX" BeforeTargets="CopySQLiteInteropFiles">
<ItemGroup>
<SQLiteInteropFiles Condition="$([MSBuild]::IsOsPlatform(Linux)) OR $([MSBuild]::IsOsPlatform(OSX))" Remove="@(SQLiteInteropFiles)" />
<SQLiteInteropFiles Condition="$([MSBuild]::IsOsPlatform(Linux))" Include="$(PkgSystem_Data_SQLite_Core)/runtimes/linux-x64/native/netstandard2.0/SQLite.Interop.*" />
<SQLiteInteropFiles Condition="$([MSBuild]::IsOsPlatform(OSX))" Include="$(PkgSystem_Data_SQLite_Core)/runtimes/osx-x64/native/netstandard2.0/SQLite.Interop.*" />
</ItemGroup>
</Target>
<ItemGroup>
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.111" GeneratePathProperty="true" />
</ItemGroup>
</Project>
Make sure to add GeneratePathProperty="true"
in the package reference. This is required for the PkgSystem_Data_SQLite_Core
property to be defined.
John Smith
Updated on June 05, 2022Comments
-
John Smith almost 2 years
I've been trying to figure this out lately. It is working on my Windows machine, where I got SQLite from NuGet, but...
When I put
System.Data.SQLite.dll
andSQLite.Interop.dll
straight from my Windows machine into Linux server it says thatSQLite.Interop.dll
is not found, but I am sure I see it next right to executable.Then I tried to compile
System.Data.SQLite.dll
with/p:UseInteropDll=false
, but with no luck. This time it says thatSystem.Data.SQLite.dll
is not found.What is this "not found" mystery?
-
O. R. Mapper almost 10 yearsUnfortunately, that is not a useful solution when the application is supposed to run on both Mono and .NET.
-
Alexandre Marcondes almost 10 yearsThe is a way to map differently on each platform, just deploy a different .config file for each platform
-
Frank over 8 years@Alexandre Marcondes, Our application is supposed to run on both Mono and .NET. How do we deploy a different .config file for Mono and .NET on Ubuntu Linux? Thank you.
-
Etienne Charland over 7 yearsThis worked for me. Don't forget to build in Release mode with /p:Configuration=Release at the end. Building EF6 wasn't necessary for me and didn't compile anyway. First I tried compiling libSQLite.Interop.on the server so but never got that to work. Now it works. However, there are "unclear drawbacks" to not using the interop library. Something to keep in mind.
-
MaurGi almost 7 yearsOk - I found the answer here: blog.wezeku.com/2016/10/09/…
-
Matt G almost 7 yearsHow do you map the DLLs? where do you put that snippet?
-
Matt G almost 7 yearsare there some other configuration settings we need to change? Im still getting the same error
-
0xced almost 6 yearsOn macOS, I noticed that copying the built
libSQLite.Interop.dylib
file (equivalent of the.so
file on Linux) into the application directory may not work. Instead I'm copyinglibSQLite.Interop.dylib
directly into/Library/Frameworks/Mono.framework/Libraries/
-
user2088807 almost 6 yearsHi, When I do that and try to launch the app I get a : "System.EntryPointNotFoundException: Unable to find an entry point named "sqlite3_key" in DLL "sqlite3"" Do you know why ?
-
tekHedd over 2 yearsI'm looking at NuGet packaging release 1.0.115, and it includes...x86 and x64. (Now in the Stub.System.Data.SQLite.Core... package) So much for linux or docker deployments. :(
-
tekHedd over 2 yearsI tried this, built without problems, version exactly matches my NuGet package version, and I get System.EntryPointNotFoundException: SIa069da76968b7553 which is... OK so the entry point is a hash? If they wanted to make it as difficult as possible, they succeeded.
-
0xced over 2 yearsIndeed, the NuGet packaging changed in recent versions of System.Data.SQLite. You can adapt the answer and use the
Stub.System.Data.SQLite.Core.NetStandard
package and$(PkgStub_System_Data_SQLite_Core_NetStandard)
instead ofSystem.Data.SQLite.Core
to get the references to the SQLite.Interop.* files.