Open
Description
Description
I'm trying to compile my project via dotnet build
, but it cannot load the System.Data.SqlClient
assembly. Wierdly enough, it does compile on Visual Studio 2019 and Intellisense works as well.
Repro steps
-
dotnet new console -lang F#
-
dotnet add package SQLProvider
-
Add this code:
module Foobar
open FSharp.Data.Sql
let [<Literal>] ConnString = "ValidConnString"
type private DB = SqlDataProvider<DatabaseVendor = Common.DatabaseProviderTypes.MSSQLSERVER,
ConnectionString = ConnString,
UseOptionTypes = true>
let private ctx = DB.GetDataContext()
And this is the .fsproj
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="src/Foobar.fs" />
<Compile Include="src/Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SQLProvider" Version="1.1.65" />
<PackageReference Include="Suave" Version="2.5.5" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
</ItemGroup>
</Project>
dotnet build
Expected behavior
Load properly the assembly.
Actual behavior
# Roughly translation...
C:\Users\Iuri L. Machado\Documents\Projects\hub\EventLogger\src\Capturer\Ability.fs(8,19): error FS3033: The Type Provider 'FSharp.Data.Sql.SqlTypeProvider' related an error: Could not load file or assembly 'System.Data.SqlClient, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the given file. [C:\Users\Iuri L. Machado\Documents\Projects\hub\EventLogger\EventLogger.fsproj]
Known workarounds
I've tried the recommended workarounds, such as, copying the DLL to the given destination dir, but without success.
Related information
- SQLServer
- Happens on Windows/Linux/Mac
- .NET Core 2.2
Activity
kunjee17 commentedon Jul 3, 2019
@imetallica can you give it a try with Paket or forcing redirect in proj file. See if that thing works?
schauerte commentedon Jul 16, 2019
I came across the same problem today.
@kunjee17: can you please give a hint on how to force redirect in the proj file?
I was curios about the difference between dotnet-cli and Visual Studio. According to the logs, the F#-compiler (fsc) is called with the exact same parameters (resolved assemblies etc) in both cases, but while Visual Studio executes it using:
dotnet build
seems to execute:Both refer to the same version ("10.4.0 for F# 4.6") on my system. Long story short: I still have no idea, what is going on, but using
msbuild
instead ofdotnet build
may present a workaround.kunjee17 commentedon Jul 16, 2019
@schauerte are you using Paket ? If yes then it is simple. You can just put force redirect near the name of package, in package dependency. You can refer the doc.
If not then it is little difficult in .net core. It is doing based on some settings in proj file. I don't remember the current name of it. Search for redirect in dot net core project. If you can't find out then let me know. Will try to search for you.
allumbra commentedon Aug 8, 2019
I'm having the same issue with dotnet cli. I'll see if I can make progress with one of the suggestions above
isthistechsupport commentedon Aug 8, 2019
Same issue, I'll try to use redirections to fix it. Will update on whether it works or not
tempestCognitor commentedon Aug 9, 2019
Having the same issue, using Paket. Builds fine in Visual Studio, but not using dotnet build (from fake). Tried
redirects: force
onSystem.Data.SqlClient
andSQLProvider
without any success, as well as copying files to the output directory suggested above. I'd appreciate any advice if anyone else has solved this, and I'm happy to provide more information if it helps.samme78 commentedon Aug 29, 2019
I also have the same issue. Has anyone found a solution?
isthistechsupport commentedon Aug 29, 2019
schauerte commentedon Aug 30, 2019
@kunjee17: No, I'm not using Paket.
According to my understanding of fsharp/#3408, the coreclr doesn't support binding redirects and that is probably the reason, I can't find documentation on how to enable it.
I wonder how Paket may be able change this and (after consulting the docs) came to the conclusion, that Paket is only able to emit binding redirects for PONs (plain old .NET projects - non core).
I didn't invest a lot of time, since for now, we can live with the
msbuild
woraround.Can anyone please guide me to some other resources if I'd taken it wrong?
isthistechsupport commentedon Aug 30, 2019
@schauerte what would be the msbuild workaround? I never found a workaround for this issue
schauerte commentedon Aug 30, 2019
@isthistechsupport since we are using Visual Studio, this issue hits us when we try to build on our ci-server.
Instead of
dotnet publish PROJECT -c=release
we now execute
msbuild PROJECT -target:publish -nologo -v:m -restore -p:configuration=release
to build the affected project there.
This works on Windows only and we have Visual Studio installed on the build server (which should not be required).
samme78 commentedon Aug 30, 2019
@schauerte thanks. The workaround is good enough for me right now.
isthistechsupport commentedon Aug 31, 2019
@schauerte sadly I'm trying to deploy a docker build to heroku, I don't think I can use VS' msbuild for that. I'll look into it, but having to deploy msbuild on top of everything else is inconvenient to say the least. Regardless, thank you for the advice!
replicaJunction commentedon Nov 8, 2019
I'm experiencing this issue as well using SQLProvider 1.1.71 and targeting .NET Core 3.0. Builds fine in VS, but crashes when running
dotnet build
. It looks like it's looking for a newer version of the SqlClient package (4.6), but it's still unable to find it.For reference, here is the error message in English:
Since I'm using Azure DevOps for
CLICI, I do have MSBuild available, but it's unfortunate that I can't build via command-line on my own system to test things likedotnet publish
instead of just building.Once again, use msbuild rather than dotnet build for compatibility re…