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
570 stars 144 forks source link

"dotnet build" fails when schema cache is present for a PostgreSQL DB #636

Closed ScottShingler closed 4 years ago

ScottShingler commented 4 years ago

Description

Running dotnet build on a project that uses SqlProvider with Npgsql while a cached schema file is present fails to build. However, the same project is able to build from Visual Studio 2019 Version 16.2.4.

Repro steps

  1. Create a basic PostgreSQL schema (single table is enough) and use SqlProvider to generate a schema cache via GetDataContext().SaveContextSchema() from Visual Studio 2019.

  2. Exit Visual Studio.

  3. Delete the bin and obj folders.

  4. Run dotnet build.

Expected behavior

The project compiles without error.

Actual behavior

Build fails with the following error:

C:\Projects\MyProj\foo\src\MyProj.Dal\Database.fs(19,5): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: The data contract type 'Microsoft.FSharp.Collections.FSharpMap`2[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[FSharp.Data.Sql.Schema.Column, FSharp.Data.SqlProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' cannot be deserialized because the required data members 'comparer, tree' were not found. [C:\Projects\MyProj\foo\src\MyProj.Dal\MyProj.Dal.fsproj]

Known workarounds

Delete the schema cache and instead have an instance of the database running. This is not ideal for CI builds.

Related information

Additional Information

Comparing the build command from Visual Studio and dotnet build reveals the following differences:

Property Visual Studio dotnet build
Path c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\commonextensions\microsoft\fsharp\fsc.exe C:\Program Files\dotnet\dotnet.exe "C:\Program Files\dotnet\sdk\2.2.401\FSharp\fsc.exe"
Version Microsoft (R) F# Compiler version 10.5.0.0 for F# 4.6 Microsoft (R) F# Compiler version 10.4.0 for F# 4.6
ScottShingler commented 4 years ago

Turns out this problem can be resolved by upgrading to .NET Core 3.0-preview9, which has F# Compiler version 10.6.0.0 for F# 4.7.

mcspud commented 4 years ago

Have you seen this problem reassert itself in .netcore 3.0 + npgsql 4.0.1 or 4.1.0? Looks like on my end the generated schema files are no longer including fields (columns) and their type maps, just the names of the tables themselves.

Thorium commented 4 years ago

See the response at #644