Skip to content

Could not load file or assembly System.Data.SqlClient if building using dotnet build #373

@daniellittledev

Description

@daniellittledev

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?

Environment

  • Windows
  • SDK 3.1.100
  • F# 4.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions