I'm having a hard time understanding why this very basic sample of F# type providers (using the SqlProvider nuget package) builds fine in Windows in the command line but in VS2022 it doesn't:
https://github.com/knocte/FSharpSqlProviderSample
As you can see, compilation in GitHubCI (in Ubuntu Linux) works too.
The errors are:
Build started...
1>------ Build started: Project: BackendDataLayer, Configuration: Debug Any CPU ------
1>C:\Users\knocte\Documents\Code\FSharpSqlProviderSample\BackendDataLayer\Access.fs(15,9): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: The type initializer for 'Npgsql.TypeMapping.BuiltInTypeHandlerResolver' threw an exception.
1>C:\Users\knocte\Documents\Code\FSharpSqlProviderSample\BackendDataLayer\Access.fs(15,9): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: The type initializer for 'Npgsql.TypeMapping.BuiltInTypeHandlerResolver' threw an exception.
1>C:\Users\knocte\Documents\Code\FSharpSqlProviderSample\BackendDataLayer\Access.fs(18,23): error FS0039: The type 'Object' does not define the field, constructor or member 'GetDataContext'.
1>C:\Users\knocte\Documents\Code\FSharpSqlProviderSample\BackendDataLayer\Access.fs(22,26): 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.
1>C:\Users\knocte\Documents\Code\FSharpSqlProviderSample\BackendDataLayer\Access.fs(23,28): 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.
1>C:\Users\knocte\Documents\Code\FSharpSqlProviderSample\BackendDataLayer\Access.fs(23,38): 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.
1>Done building project "BackendDataLayer.fsproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
To highlight the most important part of the code in the sample repository, this is the SqlDataProvider instantiation:
module Access =
[<Literal>]
let private connStr =
"Server=localhost;Port=5432;Database=runintomedb;User Id=postgres;Password='localDevPassword'"
[<Literal>]
let private resolutionPath = @"lib"
type SQL =
SqlDataProvider<Common.DatabaseProviderTypes.POSTGRESQL, connStr, Owner="public, admin, references", UseOptionTypes=true, ResolutionPath=resolutionPath>
And this is the resolutionPath tweaks I had to do to the .fsproj file (which, again, work fine when using dotnet build in the command line):
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<MakeDir Directories="lib" />
<Copy
Condition="!Exists('lib\Microsoft.Bcl.AsyncInterfaces.dll')"
SourceFiles="..\packages\microsoft.bcl.asyncinterfaces\6.0.0\lib\netstandard2.0\Microsoft.Bcl.AsyncInterfaces.dll"
DestinationFolder="lib"
/>
<Copy
Condition="!Exists('lib\Microsoft.Bcl.HashCode.dll')"
SourceFiles="..\packages\microsoft.bcl.hashcode\1.1.1\lib\netstandard2.0\Microsoft.Bcl.HashCode.dll"
DestinationFolder="lib"
/>
<Copy
Condition="!Exists('lib\System.Threading.Tasks.Extensions.dll')"
SourceFiles="..\packages\system.threading.tasks.extensions\4.5.4\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll"
DestinationFolder="lib"
/>
<Copy
Condition="!Exists('lib\System.Threading.Channels.dll')"
SourceFiles="..\packages\system.threading.channels\6.0.0\lib\netstandard2.0\System.Threading.Channels.dll"
DestinationFolder="lib"
/>
</Target>