4

I'm a beginner in both F# and the .Net world, I'm trying to make this F# script work:

#r "./packages/SQLProvider/lib/netstandard2.0/FSharp.Data.SqlProvider.dll"
#r "./packages/SQLProvider/lib/netstandard2.0/netstandard.dll"
#r "./packages/Npgsql/lib/netstandard2.0/Npgsql.dll"
open FSharp.Data.Sql
open Npgsql
let [<Literal>] ConnString = 
 "Host=localhost;" +
 "Port=5431;" +
 "Database=suavetododb;" +
 "Username=postgres;" +
 "Password=postgres"
let [<Literal>] DbVendor = Common.DatabaseProviderTypes.POSTGRESQL
let [<Literal>] ResPath = @"./packages/Npgsql/lib/netstandard2.0"
type Sql =
 SqlDataProvider<
 DbVendor,
 ConnString,
 "",
 ResPath,
 1000,
 true>

This is the error I get:

error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not resolve field token 0x04000523, due to: Could not load type of field 'Npgsql.NpgsqlConnection+d__28:<>u__2' (7) due to: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. assembly:System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 type: member:(null) signature: assembly:(my_filesystem)/API/packages/Npgsql/lib/netstandard2.0/Npgsql.dll type:d__28 member:(null) signature:

Which is weird, since Npgsql is actually imported (so the last #r actually works).

The database is up via docker:

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4704763ec2ba suave_rezoom_db:0.1 "docker-entrypoint.s..." 25 hours ago Up 2 hours 0.0.0.0:5431->5432/tcp todo_rezoom_1

Also, the project was generated via the .Net Core 2.1.200 and is running on Linux.

asked Jun 5, 2018 at 16:36

1 Answer 1

6

This is because the type provider needs to resolve dependencies of the third-party driver (Npgsql in this case), and it can't because it doesn't have access to the full dependency tree like NuGet (or Paket) does. You need to copy System.Threading.Tasks.Extensions.dll to the same folder where Npgsql.dll sits (your ResPath) so that the type provider can resolve that assembly.

Once you do that, you'll find that you also need to copy System.Runtime.CompilerServices.Unsafe.

answered Jul 19, 2018 at 4:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.