fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
564 stars 144 forks source link

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

Open jim108dev opened 2 years ago

jim108dev commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

jim108dev commented 2 years ago

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?

alexzandros commented 1 month ago

@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

    I'm experiencing the same problem, I'm trying to use the provider on a Win 11 machine using Rider. And although the inerop file is located in \SolutionName\Project\bin\Debug\net8.0\runtimes\win-x64\native, the provider reports not being able to locate it.

I think the docs aren't clear enough about where the SQLite.Interop.dll file should be copied to.

PS. I copied the SQLite.Interop.dll file into USERDIRECTORY\.nuget\packages\stub.system.data.sqlite.core.netstandard\1.0.118\lib\netstandard2.0 and it worked. I think the Data.SQLite team changed some parts of the NuGet package setup, so maybe docs for the provider needs to be updated.

Thorium commented 1 month ago

ResolutionPath is a static parameter to SqlProvider like connectionstring is, so you pick a folder. Often easier to point a separate folder instead of Nuget path.

Even if your machine and your OS are x64, it might be that your compiler is running on x86.