ericsink / SQLitePCL.raw

A Portable Class Library (PCL) for low-level (raw) access to SQLite
Apache License 2.0
521 stars 108 forks source link

.NET Framework 4.6.2, run with Mono on Ubuntu #604

Open SanteR1 opened 3 weeks ago

SanteR1 commented 3 weeks ago

What version of SQLitePCLRaw are you using? 2.1.9 If you are using one of the SQLitePCLRaw bundle packages, which one? SQLitePCLRaw.bundle_e_sqlite3 What platform are you running on? What operating system? Which version? What CPU? Run Mono on Ubuntu, Mono JIT compiler version 6.8.0.105, Ubuntu 22.04.4 LTS. Build on Windows 10x64, Intel Core i7-4790K What target framework are you building for? net 4.6.2 Are you on .NET Framework or the newer stuff (.NET Core, .NET 5+, etc)? net 4.6.2 Are you using the command line, or an IDE? Which IDE? Which version of that IDE? Visual Studio 2022 Is this problem something that just started happening? For example, were things working well for you and then you updated something and then the problem showed up? What changed? First with Mono on Ubuntu. On Windows fine work. What is the exact error message you are seeing when the problem happens?

mono ./ConsoleApp2.exe
System.Exception: Library e_sqlite3 not found
plat: dlopen
suffix: SO
possibilities (2):
    1) /home/santer/Release/runtimes/linux-x64/native/libe_sqlite3.so
    2) /home/santer/Release/libe_sqlite3.so
dlopen TryLoad: /home/santer/Release/runtimes/linux-x64/native/libe_sqlite3.so
thrown: System.DllNotFoundException: dl assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) SQLitePCL.NativeLibrary+NativeLib_dlopen.dlopen(string,int)
  at SQLitePCL.NativeLibrary.TryLoad (System.String name, SQLitePCL.NativeLibrary+Loader plat, System.Action`1[T] log, System.IntPtr& h) [0x00069] in <e9bb8263add7423ea112c3ab411d5a61>:0
dlopen TryLoad: /home/santer/Release/libe_sqlite3.so
thrown: System.DllNotFoundException: dl assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) SQLitePCL.NativeLibrary+NativeLib_dlopen.dlopen(string,int)
  at SQLitePCL.NativeLibrary.TryLoad (System.String name, SQLitePCL.NativeLibrary+Loader plat, System.Action`1[T] log, System.IntPtr& h) [0x00069] in <e9bb8263add7423ea112c3ab411d5a61>:0
NOT FOUND

  at SQLitePCL.NativeLibrary.Load (System.String libraryName, System.Reflection.Assembly assy, System.Int32 flags) [0x00058] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at SQLitePCL.Batteries_V2.MakeDynamic (System.String name, System.Int32 flags) [0x00010] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at SQLitePCL.Batteries_V2.DoDynamic_cdecl (System.String name, System.Int32 flags) [0x00000] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at SQLitePCL.Batteries_V2.Init () [0x00000] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at ConsoleApp2.Program.Insert () [0x00000] in <9099a5d5f65441eeab060f19a181d213>:0

Are you using PackageReference or packages.config? PackageReference If you are using mobile platforms, are you on classic/legacy Xamarin or on .NET 6 and higher? .NET Framework 4.6.2 Sometimes other packages using SQLitePCLRaw cause problems when they are mixed together. What other packages are you including in your project?

Microsoft.Data.Sqlite.Core
SQLitePCLRaw.core
SQLitePCLRaw.bundle_e_sqlite3

How can we reproduce the problem you are seeing? Your issue will get attention much faster if you attach a minimal reproduction sample project. https://github.com/SanteR1/ConsoleApp2

ericsink commented 3 weeks ago

When using mono, it may be necessary to manually copy the native library into the proper place (like your build output directory).

SanteR1 commented 3 weeks ago

@ericsink Of course I tried to copy manually from .nuget\packages\sqlitepclraw.lib.e _ sqlite3\2.1.9\runtimes\linux-x64\native to /home/santer/Release/runtimes/linux-x64/native/ and to /home/santer/Release/

ericsink commented 3 weeks ago

There are two possibilities:

  1. It can't find the file
  2. It can't find a dependency of the file

I wonder about the difference between e_sqlite3.so and libe_sqlite3.so on your machine.

Or...

Try ldd e_sqlite.so and look for dependencies not available on your machine. Like maybe your C library is too old or too new.

SanteR1 commented 3 weeks ago

Very strange

santer@DESKTOP-1SSN6VL:~/Release$ mono ConsoleApp2.exe
System.Exception: Library e_sqlite3 not found
plat: dlopen
suffix: SO
possibilities (2):
    1) /home/santer/Release/runtimes/linux-x64/native/libe_sqlite3.so
    2) /home/santer/Release/libe_sqlite3.so
dlopen TryLoad: /home/santer/Release/runtimes/linux-x64/native/libe_sqlite3.so
thrown: System.DllNotFoundException: dl assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) SQLitePCL.NativeLibrary+NativeLib_dlopen.dlopen(string,int)
  at SQLitePCL.NativeLibrary.TryLoad (System.String name, SQLitePCL.NativeLibrary+Loader plat, System.Action`1[T] log, System.IntPtr& h) [0x00069] in <e9bb8263add7423ea112c3ab411d5a61>:0
dlopen TryLoad: /home/santer/Release/libe_sqlite3.so
thrown: System.DllNotFoundException: dl assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) SQLitePCL.NativeLibrary+NativeLib_dlopen.dlopen(string,int)
  at SQLitePCL.NativeLibrary.TryLoad (System.String name, SQLitePCL.NativeLibrary+Loader plat, System.Action`1[T] log, System.IntPtr& h) [0x00069] in <e9bb8263add7423ea112c3ab411d5a61>:0
NOT FOUND

  at SQLitePCL.NativeLibrary.Load (System.String libraryName, System.Reflection.Assembly assy, System.Int32 flags) [0x00058] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at SQLitePCL.Batteries_V2.MakeDynamic (System.String name, System.Int32 flags) [0x00010] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at SQLitePCL.Batteries_V2.DoDynamic_cdecl (System.String name, System.Int32 flags) [0x00000] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at SQLitePCL.Batteries_V2.Init () [0x00000] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at ConsoleApp2.Program.Insert () [0x00000] in <fe06bce1ea034df5871fd74144c24654>:0
santer@DESKTOP-1SSN6VL:~/Release$ ldd /home/santer/Release/libe_sqlite3.so
        linux-vdso.so.1 (0x00007fffedd3c000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f238c5d0000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f238cb3f000)
santer@DESKTOP-1SSN6VL:~/Release$ ldd ./libe_sqlite3.so
        linux-vdso.so.1 (0x00007ffffe521000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f355ffd0000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f3560613000)
santer@DESKTOP-1SSN6VL:~/Release$ ldd ./runtimes/linux-x64/native/libe_sqlite3.so
        linux-vdso.so.1 (0x00007fffd4a31000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc7b81d0000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fc7b88c3000)
ericsink commented 3 weeks ago

Could this be an LD_LIBRARY_PATH problem?

ericsink commented 3 weeks ago

Actually that probably doesn't make sense.

SanteR1 commented 3 weeks ago

I did not initially install $LD_LIBRARY_PATH, but I have now checked

santer@DESKTOP-1SSN6VL:~/Release$ echo $LD_LIBRARY_PATH

santer@DESKTOP-1SSN6VL:~/Release$ export LD_LIBRARY_PATH=/home/santer/Release:$LD_LIBRARY_PATH
santer@DESKTOP-1SSN6VL:~/Release$ echo $LD_LIBRARY_PATH
/home/santer/Release:
santer@DESKTOP-1SSN6VL:~/Release$ mono ConsoleApp2.exe
System.Exception: Library e_sqlite3 not found
plat: dlopen
suffix: SO
possibilities (2):
    1) /home/santer/Release/runtimes/linux-x64/native/libe_sqlite3.so
    2) /home/santer/Release/libe_sqlite3.so
dlopen TryLoad: /home/santer/Release/runtimes/linux-x64/native/libe_sqlite3.so
thrown: System.DllNotFoundException: dl assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) SQLitePCL.NativeLibrary+NativeLib_dlopen.dlopen(string,int)
  at SQLitePCL.NativeLibrary.TryLoad (System.String name, SQLitePCL.NativeLibrary+Loader plat, System.Action`1[T] log, System.IntPtr& h) [0x00069] in <e9bb8263add7423ea112c3ab411d5a61>:0
dlopen TryLoad: /home/santer/Release/libe_sqlite3.so
thrown: System.DllNotFoundException: dl assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) SQLitePCL.NativeLibrary+NativeLib_dlopen.dlopen(string,int)
  at SQLitePCL.NativeLibrary.TryLoad (System.String name, SQLitePCL.NativeLibrary+Loader plat, System.Action`1[T] log, System.IntPtr& h) [0x00069] in <e9bb8263add7423ea112c3ab411d5a61>:0
NOT FOUND

  at SQLitePCL.NativeLibrary.Load (System.String libraryName, System.Reflection.Assembly assy, System.Int32 flags) [0x00058] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at SQLitePCL.Batteries_V2.MakeDynamic (System.String name, System.Int32 flags) [0x00010] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at SQLitePCL.Batteries_V2.DoDynamic_cdecl (System.String name, System.Int32 flags) [0x00000] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at SQLitePCL.Batteries_V2.Init () [0x00000] in <e9bb8263add7423ea112c3ab411d5a61>:0
  at ConsoleApp2.Program.Insert () [0x00000] in <fe06bce1ea034df5871fd74144c24654>:0
santer@DESKTOP-1SSN6VL:~/Release$
Jonarw commented 4 days ago

I have the exact same problem using SQLitePCLRaw.bundle_e_sqlite3 v2.1.10 on a Raspberry Pi 5. On Windows / .NET 4.8 it works fine. On Raspberry Pi OS / Mono I get the exact same error message as above. I also manually had to copy libe_sqlite3.so to the output directory, but even then the error persisted.

ldd output:

ldd ./libe_sqlite3.so
    linux-vdso.so.1 (0x00007ffee0258000)
    libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x00007ffedff00000)
    /lib/ld-linux-aarch64.so.1 (0x00007ffee0220000)