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 compile using Visual Studio but works with dotnet #783

Closed dlidstrom closed 1 year ago

dlidstrom commented 1 year ago

I am trying to compile a minimal sample using Visual Studio 17.0.17. I get an error about not being able to load the requested types:

1>C:\Git\SqlProviderTest\Program.fs(18,5): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.Details: 
Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Data.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Diagnostics.Tracing, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Threading, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.ComponentModel.TypeConverter, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Current execution platform: .NETFramework,Version=v4.7.2

The program looks like this:

open FSharp.Data.Sql
open FSharp.Data.Sql.Common

[<Literal>]
let DbVendor = DatabaseProviderTypes.POSTGRESQL

[<Literal>]
let ConnString =
    "Host=localhost;Port=5432;Database=prisma;Username=prisma;Password=prisma"

[<Literal>]
let ResPath = __SOURCE_DIRECTORY__ + @"\lib"

[<Literal>]
let IndivAmount = 1000

type DatabaseProvider =
    SqlDataProvider<DatabaseVendor=DbVendor, ConnectionString=ConnString, ResolutionPath=ResPath, IndividualsAmount=IndivAmount, UseOptionTypes=true, Owner="log, bits">

printfn "Hello, World"

and the project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6</TargetFramework>
    <LangVersion>latest</LangVersion>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>
  <PropertyGroup>
    <ServerGarbageCollection>true</ServerGarbageCollection>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="SQLProvider" Version="1.2.11" />
    <PackageReference Include="Npgsql" Version="6.0.4" />
  </ItemGroup>
</Project>

Note that this builds fine with dotnet:

PS C:\Git\SqlProviderTest> dotnet build
MSBuild version 17.4.0+18d5aef85 for .NET
  Determining projects to restore...
  Restored C:\Git\SqlProviderTest\SqlProviderTest.fsproj (in 684 ms).
  SqlProviderTest -> C:\Git\SqlProviderTest\bin\Debug\net6\SqlProviderTest.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:10.97

I did not (yet) place any binaries in the lib folder (is this the problem?). This was all done using installed dotnet 7.0.101 on Windows. How come this works using dotnet but not Visual Studio?

dlidstrom commented 1 year ago

Update: I forgot to try with the latest version but the same seems to happen with 1.3.5.

Thorium commented 1 year ago

I think the problem is Npgsql dependencies not being in the lib-folder.

dlidstrom commented 1 year ago

Where is the best place to copy System.{Runtime,Data.Common,Diagnostics.Tracing,Threading,ComponentModel.TypeConverter} from? This seems to be a common task and there are prepared prebuild scripts for it?

I have this script which seems to be all that is needed when using dotnet on my old Macbook Pro:

$ErrorActionPreference = "Stop"

$packagesAndPaths=@(
  @{
    name = "System.Runtime.CompilerServices.Unsafe"
    path = "6.0.0/lib/netstandard2.0"
  }
)

$nugetPath=(dotnet nuget locals global-packages --list).Split(' ')[1]
New-Item -ItemType Directory -Name lib -Force

foreach ($item in $packagesAndPaths) {
  $nugetDll = "$($item.name).dll"
  $fullPath = "$nugetPath$($item.name.ToLower())/$($item.path)/$nugetDll"
  Copy-Item $fullPath ./lib
  " $fullPath > Copied $nugetDll into lib for type provider."
}
dlidstrom commented 1 year ago

Seems to be documented here: https://github.com/fsprojects/SQLProvider/tree/master/tests/SqlProvider.Core.Tests/Postgres Would've been great if this documentation was more visible, for example here: https://fsprojects.github.io/SQLProvider/core/postgresql.html.