Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any 2023 tricks for running on Windows? #427

Open
cr3wdayt5p opened this issue Mar 29, 2023 · 3 comments
Open

Any 2023 tricks for running on Windows? #427

cr3wdayt5p opened this issue Mar 29, 2023 · 3 comments

Comments

@cr3wdayt5p
Copy link

cr3wdayt5p commented Mar 29, 2023

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.

@smoothdeveloper
Copy link
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.

@cr3wdayt5p
Copy link
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.

@smoothdeveloper
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants