fsprojects / fsprojects/FSharp.Data.SqlClient
Could not load file or assembly `System.Data.SqlClient` if building using `dotnet build`
Nobody has claimed this yet.
- Dominant language
- F#
- Stars
- 206
- Forks
- 66
- PR merge metrics
- No merged PRs in 30d
Description
Description
When building a netcoreapp3.1 or netstandard2.1 library, the build will succeed when using Visual Studio 2019 but will fail when built via dotnet build.
Error details:
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 should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
Repro steps
Create a dotnet core library which uses the type provider.
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors></WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
<PackageReference Include="FSharp.Data.SqlClient" Version="2.0.6" />
</ItemGroup>
Expected behavior
I'd expect the non-reference version of System.Data.SqlClient to be loaded and the build to succeed.
Actual behavior
The type provider is unable to load the System.Data.SqlClient assembly as it is a reference assembly.
Known workarounds
Forcing the project to use the full framework compiler seems to work, but you need to set some properties for this to work in .netcore3.0
<PropertyGroup>
<DisableAutoSetFscCompilerPath>true</DisableAutoSetFscCompilerPath>
<DotNetFscToolPath></DotNetFscToolPath>
<DotnetFscCompilerPath></DotnetFscCompilerPath>
</PropertyGroup>
<Import Project="fsc.props" />
Related information
I found a number of what appear to be related but older issues. As far as i can tell .NET Standard 2.0 type providers can now be used when the F# compiler is running on .NET Core. So I believe this is an issue with loading the correct System.Data.SqlClient assembly?
- https://github.com/dotnet/fsharp/issues/3298
- https://github.com/fsprojects/SQLProvider/issues/529
- https://medium.com/@dsincl12/f-with-net-core-2-0-4-and-sqlprovider-d8f071119da9
- https://github.com/fsprojects/FSharp.Data.SqlClient/issues/318
Environment
- Windows
- SDK 3.1.100
- F# 4.7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal netcoreapp3.1 or netstandard2.1 library described in the repro steps, using the System.Data.SqlClient and FSharp.Data.SqlClient package references, and run dotnet build. Investigate how the type provider resolves the assembly during the .NET Core compiler path; done means the build succeeds without requiring the full-framework compiler workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp, sql
- Domain
- build-system, compilers, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100