System.DllNotFoundException on Mono SQLite

对着背影说爱祢 提交于 2019-11-28 21:44:19
Alexandre Marcondes

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>

No code changes necessary. You can build it yourself.

  1. apt-get install build-essentials unzip
  2. Download the SQLITE source code - you want the full source code. Currently called sqlite-netFx-full-source-1.0.104.0.zip.
  3. unzip and cd Source,
  4. chmod +x the compile-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.
  5. Copy this .so file to the directory that has your application in
  6. Run your application as normal.
  7. Note: Ensure that your SQLite database and the directory it's inside of are writable by the user you're trying to run as.

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 methodSystem.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...

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!