Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load shared library 'SQLite.Interop.dll' #755

Open
jim108dev opened this issue Dec 9, 2021 · 3 comments
Open

Unable to load shared library 'SQLite.Interop.dll' #755

jim108dev opened this issue Dec 9, 2021 · 3 comments

Comments

@jim108dev
Copy link

jim108dev commented Dec 9, 2021

Describe the bug
I can't get most basic example like https://fsprojects.github.io/SQLProvider/core/sqlite.html working.

To Reproduce
Steps to reproduce the behavior:

  1. Create new console application.

    dotnet new console -lang F# -o SQLite
    cd SQLite
    dotnet add package SQLProvider
    dotnet add package System.Data.SQLite
  2. Build sqlite-netFx

    cd /tmp
    mkdir sqlite-netFx
    cd sqlite-netFx
    wget https://system.data.sqlite.org/downloads/1.0.115.5/sqlite-netFx-full-source-1.0.115.5.zip
    unzip sqlite-netFx-full-source-1.0.115.5.zip
    cd Setup
    sh compile-interop-assembly-debug.sh
    cp -rf bin/2013/Release/bin ~/github/fsharp_sqlprovider/SQLite/lib
  3. Add lib to SQLite.fsproj (in ItemGroup)

    <None Include="lib/libSQLite.Interop.so">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  4. Copy northwindEF.db from SQLProvider to SQLite/db

  5. Add to Program.fs

    open System
    open FSharp.Data.Sql
    
    [<Literal>]
    let connectionString =
        @"Data Source="
        + __SOURCE_DIRECTORY__
        + @"/db/northwindEF.db;Version=3;Read Only=false;FailIfMissing=True;"
    
    //If System.Data.SQLite.dll is in the location where NuGet places it by default, you don't have to submit the ResolutionPath parameter at all, but you still need to copy the interop libraries as described above.
    
    type sql =
        SqlDataProvider<Common.DatabaseProviderTypes.SQLITE, connectionString, CaseSensitivityChange=Common.CaseSensitivityChange.ORIGINAL, SQLiteLibrary=Common.SQLiteLibrary.SystemDataSQLite>
  6. Run

    dotnet run
    /home/a/github/fsharp_sqlprovider/SQLite/Program.fs(20,5): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Unable to load shared library 'SQLite.Interop.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libSQLite.Interop.dll: cannot open shared object file: No such file or directory [/home/a/github/fsharp_sqlprovider/SQLite/SQLite.fsproj]
    /home/a/github/fsharp_sqlprovider/SQLite/Program.fs(20,5): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Unable to load shared library 'SQLite.Interop.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libSQLite.Interop.dll: cannot open shared object file: No such file or directory [/home/a/github/fsharp_sqlprovider/SQLite/SQLite.fsproj]
    
    The build failed. Fix the build errors and run again.
    
  7. System information

    dotnet --info
    .NET SDK (reflecting any global.json):
    Version:   5.0.403
    Commit:    bf9d168ac2
    
    Runtime Environment:
    OS Name:     ubuntu
    OS Version:  20.04
    OS Platform: Linux
    RID:         ubuntu.20.04-x64
    Base Path:   /usr/share/dotnet/sdk/5.0.403/
    
    Host (useful for support):
    Version: 5.0.12
    Commit:  7211aa01b3
    
    .NET SDKs installed:
    3.1.415 [/usr/share/dotnet/sdk]
    5.0.403 [/usr/share/dotnet/sdk]
    
    .NET runtimes installed:
    Microsoft.AspNetCore.App 3.1.21 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.NETCore.App 3.1.21 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
    
    To install additional .NET runtimes or SDKs:
    https://aka.ms/dotnet-download
    

Should this work? Is the documentation up to date? Which point am I missing?

Thank you!

@Thorium
Copy link
Member

Thorium commented Dec 9, 2021

You need to set the ResolutionPath when working with SQLite.
https://fsprojects.github.io/SQLProvider/core/parameters.html#ResolutionPath

The first thing to check with SQLite is that are you running in x64 or x86 mode, and are your reference library dlls in the resolutionpath for the same x64 or x86.

@jim108dev
Copy link
Author

jim108dev commented Dec 10, 2021

@Thorium Thank you for the quick reply!

At https://fsprojects.github.io/SQLProvider/core/sqlite.html
it is stated:

If System.Data.SQLite.dll is in the location where NuGet places it by default, you don't have to submit the ResolutionPath parameter at all, but you still need to copy the interop libraries as described above.

  • Every command I have used is plain vanilla like described above, thus this sentence applies, doesn't it?
  • Dotnet info shows RID: ubuntu.20.04-x64 and I haven't specified the cpu in my project file, I guess its x64 then.
  • file lib/libSQLite.Interop.so
    lib/libSQLite.Interop.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=5adfce885200ee6faa387376f310e16059940c50, with debug_info, not stripped
    

@jim108dev
Copy link
Author

jim108dev commented Dec 12, 2021

I have tried to get it working under windows with
https://github.com/fsprojects/SQLProvider/tree/master/tests/SqlProvider.Core.Tests/SQLite

I had to change the copy path to the dlls:

    <Exec Command="xcopy ..\..\..\packages\tests\SQLitePCLRaw.core\lib\netstandard2.0\SQLitePCLRaw.core.dll temp\ /y" />
    <Exec Command="xcopy ..\..\..\packages\tests\SQLitePCLRaw.lib.e_sqlite3\runtimes\win10-x64\nativeassets\uap10.0\e_sqlite3.dll temp\ /y" />
    <Exec Command="xcopy ..\..\..\packages\tests\SQLitePCLRaw.bundle_green\lib\net461\SQLitePCLRaw.batteries_v2.dll temp\ /y" />
    <Exec Command="xcopy ..\..\..\packages\tests\Microsoft.Data.Sqlite.Core\lib\netstandard2.0\Microsoft.Data.Sqlite.dll temp\ /y" />

and I get

C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\Program.fs(25,11): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not load file or assembly 'SQLitePCLRaw.core, Version=2.0.3.851, Culture=neutral, PublicKeyToken=1488e028ca7ab535' or one of its dependencies. The system cannot find the file specified., Path: C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\temp (You are NOT running on x64.) [C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\SqlProvider.Core.Tests.fsproj]
C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\Program.fs(25,11): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not load file or assembly 'SQLitePCLRaw.core, Version=2.0.3.851, Culture=neutral, PublicKeyToken=1488e028ca7ab535' or one of its dependencies. The system cannot find the file specified., Path: C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\temp (You are NOT running on x64.) [C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\SqlProvider.Core.Tests.fsproj]
C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\Program.fs(30,18): error FS0039: The type 'Object' does not define the field, constructor or member 'GetDataContext'. [C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\SqlProvider.Core.Tests.fsproj]
C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\Program.fs(33,24): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. [C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\SqlProvider.Core.Tests.fsproj]
C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\Program.fs(34,20): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. [C:\Users\User\Documents\github\SQLProvider-master\tests\SqlProvider.Core.Tests\SQLite\SqlProvider.Core.Tests.fsproj]

The build failed. Fix the build errors and run again.

I guess Microsoft.Data.Sqlite.dll is x86. How do I get the x64 version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants