Skip to content

Any 2023 tricks for running on Windows? #427

Open

Description

@cr3wdayt5p

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.

Activity

  1. smoothdeveloper commented on Mar 30, 2023

    @smoothdeveloper
    Collaborator

    @cr3wdayt5p thanks for the extensive and detailed bug report. I'll try to investigate it, you can also check if the issue is the same with the dotnet framework, if you have ability to target it.

    In the meantime, since you mention it works fine on Linux and macOs and fails on Windows, I'd suggest the issue be reported to the dotnet sdk itself, either it is an issue in the dotnet sdk, or in the System.Data.SqlClient package, which I think is also part of the SDK.

    I don't think there is anything platform specific in this repository that would cause the issue specifically.

    It could also be that the F# compiler on windows is doing something different in context of compile time loading of dependencies that the type provider brings in the compilation.

  2. cr3wdayt5p commented on Mar 30, 2023

    @cr3wdayt5p
    Author

    I don't have the ability to target dotnet framework. But I did try both net6.0 and net7.0 – but the result was the same.

    My guess is that System.Data.SqlClient somehow runs in a different context when used by the type provider vs. when used directly. So I am hoping that somebody has experienced the same issue and found a solution, e.g. including some missing SNI dll or something.

    But the first step to really investigate this issue would be to make the type provider output the full content of the exception thrown by System.Data.SqlClient.TdsParser.

  3. smoothdeveloper commented on Mar 30, 2023

    @smoothdeveloper
    Collaborator

    @cr3wdayt5p thanks for additional details.

    You may bring your own feedback on those issues, or try to open specific one, asking about native dependency loading in context of type providers on dotnet/fsharp.

    Also, please consider if dotnet/fsharp#4956 and dotnet/fsharp#10323 have some relevancy, you could expand your perspective on the discussions there.

    I'm also facing issues related to this and other type providers in Rider since recent dotnet sdk (such as loading of System.Runtime.Caching, etc.), I think they all pertains to breaking changes in dotnet SDK.

    If there is a known way of fixing it in this particular type provider disregarding of the SDK, I'd be glad to make a new release with such fix.

  4. github-actions commented on Mar 12, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    The root cause of The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception on Windows is a native DLL loading issue.

    What's happening

    System.Data.SqlClient depends on sni.dll (SQL Server Native Interface) — a native Windows DLL that lives in the NuGet package under runtimes/win/lib/native/. When a regular application runs on Windows, the .NET runtime's native library probing finds this DLL. However, when the F# compiler loads the type provider at design time (i.e., during dotnet build), it runs in its own process with different probing roots and does not automatically pick up runtime native assets from NuGet package directories.

    This is why:

    • macOS/Linux works — the Unix-variant native libraries happen to be found or the transport layer differs
    • Direct use of System.Data.SqlClient in your application works — your application's output directory has the native DLL copied into it at publish time
    • Type provider on Windows fails — the compiler's design-time host does not set up the NuGet runtimes/win/lib/native probing path

    Short-term workarounds

    1. Copy sni.dll from ~/.nuget/packages/system.data.sqlclient/(version)/runtimes/win/lib/native/ next to the FSharp.Data.SqlClient.DesignTime.dll in your .nuget package cache.
    2. Use -r: to reference the implementation DLL as you already do, and additionally set DOTNET_LIBRARY_PATH to point at the directory containing sni.dll before running dotnet build.

    Long-term path forward

    This is one of the known limitations of System.Data.SqlClient in type-provider design-time contexts. The planned migration to Microsoft.Data.SqlClient (see #445 and #444) uses a managed transport layer (SNI.cs-based) that avoids the native DLL loading problem entirely and should resolve this class of failure on Windows. That migration is actively in progress.

    Generated by Repo Assist · ◷

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions