Error building project that uses FSharp.Data.Sql.SqlTypeProvider


I have a net7.0 class library which includes the following packages

<Project Sdk="Microsoft.NET.Sdk">


        <Compile Include="ServerSampleData.fs" />
        <Compile Include="MsSql\EntityMapper.fs" />
        <Compile Include="MsSql\DataService.fs" />
        <PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
        <PackageReference Include="mongocsharpdriver" Version="2.19.1" />
        <PackageReference Include="MongoDB.Driver" Version="2.19.1" />
        <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
        <PackageReference Include="Serilog" Version="2.12.0" />
        <PackageReference Include="SQLProvider" Version="1.3.8" />

The entitymapper.cs has the following module

module DataModel =
    let [<Literal>] dbVendor = Common.DatabaseProviderTypes.MSSQLSERVER
    let [<Literal>] connString = ".."
    let [<Literal>] useOptTypes  = NullableColumnType.OPTION
    let [<Literal>] contextSchemaPath  = @"c:\temp\theschema.schema"

    type sql = SqlDataProvider<dbVendor, connString, UseOptionTypes = useOptTypes, ContextSchemaPath=contextSchemaPath>

the dataprovider.fs is getting the context like that.

let context = sql.GetDataContext(storage.ConnectionString)

This is working ONLY working when I build it with Visual Studio, using “dotnet build” or Jetbrains Rider on my windows 10 machine or building via the azure pipelines with a Microsoft hosted agent it fails. I am using this pool in the pipeline.

vmImage: “windows-latest”

There I get the error

##[error]EntityMapper.fs(15,16): Error FS3033: The type provider ‘FSharp.Data.Sql.SqlTypeProvider’ reported an error: Microsoft.Data.SqlClient is not supported on this platform.

Anyone has an idea what I am missing here?

Honestly, the official SqlProvider has been in a sorry state for a while, with the several recurring dev- and run-time errors. I’ve definitely run into this particular one before - looks like there’s some GitHub threads for it: [Microsoft,System].Data.SqlClient is not supported on this platform · Issue #786 · fsprojects/SQLProvider · GitHub. Hopefully something here helps.

Thanks @jwosty . It took me a while to generate the schema to be independent from a running local sql database.
I did switch to SqlHydra now. Its quite a nice experience. Well documented. You generate the types and you can use that. It took minimal effort to change my current logic from the expression sqlprovider used to the ones hydra uses.
Quite a nice experience for now.

Will mark that as a solution but its not the answer to the original problem.