What are the tips, tricks, and hacks for making FSharp.Data.SqlClient run on Windows in 2023? In other words: What is smallest working example project for Windows?
I have been happily using FSharp.Data.SqlClient in a project that I develop on macOS and deploy to Azure Functions (Linux). I have had no problems after finding the initial trick to load System.Data.SqlClient (#373 (comment)).
But now I would like my colleagues with Windows machine to be able contribute to the project. But I don't know how to solve the build error: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.
Repro Steps
OS: Windows 10
.NET SDK: 7.0.202
Test.fs
open FSharp.Data
[<Literal>]
let connStr = "...insert-connnection-string-here..."
type MyCommand = SqlCommandProvider<"SELECT 42 as myNumber, 'hello' as myString", connStr>
(new MyCommand(connStr)).Execute() |> printfn "%A"
Test.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="Test.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Data.SqlClient" Version="2.1.2" />
</ItemGroup>
<!-- tricks -->
<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.8.5">
<ExcludeAssets>compile</ExcludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<OtherFlags>$(OtherFlags) -r:"C:\Users\my_user_name\.nuget\packages\system.data.sqlclient\4.8.5\runtimes\win\lib\netstandard2.0\System.Data.SqlClient.dll"</OtherFlags>
</PropertyGroup>
</Project>
Run: dotnet build
Expected behavior
The build should succeed and work on Windows just like it does on macOS (with adjusted path to System.Data.SqlClient.dll).
Actual behavior
Build error:
Test.fs(7,18): error FS3033: The type provider 'FSharp.Data.
SqlCommandProvider' reported an error: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.
There are no further details about the exception thrown by System.Data.SqlClient.TdsParser (even using dotnet build -v:d). Does anyone know how to get more details? Or completely solve this issue?
Related information
The trick to provide the System.Data.SqlClient.dll (#373 (comment)) works as excepted and solves this error: Test.fs(7,18): error FS3033: The type provider 'FSharp.Data. SqlCommandProvider' reported an error: Could not load file or assembly 'System.Data.SqlClient, Version=4.4.0.0, Culture =neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies cannot be loaded for execution. (0x80131058)
The connection string used for this experiment has been tested with a small project using System.Data.SqlClient directly, and it works as expected on the Windows machine.
What are the tips, tricks, and hacks for making
FSharp.Data.SqlClientrun on Windows in 2023? In other words: What is smallest working example project for Windows?I have been happily using
FSharp.Data.SqlClientin a project that I develop on macOS and deploy to Azure Functions (Linux). I have had no problems after finding the initial trick to loadSystem.Data.SqlClient(#373 (comment)).But now I would like my colleagues with Windows machine to be able contribute to the project. But I don't know how to solve the build error:
The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.Repro Steps
OS: Windows 10
.NET SDK: 7.0.202
Test.fs
Test.fsproj
Run:
dotnet buildExpected behavior
The build should succeed and work on Windows just like it does on macOS (with adjusted path to
System.Data.SqlClient.dll).Actual behavior
Build error:
There are no further details about the exception thrown by
System.Data.SqlClient.TdsParser(even usingdotnet build -v:d). Does anyone know how to get more details? Or completely solve this issue?Related information
The trick to provide the
System.Data.SqlClient.dll(#373 (comment)) works as excepted and solves this error:Test.fs(7,18): error FS3033: The type provider 'FSharp.Data. SqlCommandProvider' reported an error: Could not load file or assembly 'System.Data.SqlClient, Version=4.4.0.0, Culture =neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies cannot be loaded for execution. (0x80131058)The connection string used for this experiment has been tested with a small project using
System.Data.SqlClientdirectly, and it works as expected on the Windows machine.