SQLProvider
SQLProvider copied to clipboard
Error when compiling on console
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
@imetallica can you give it a try with Paket or forcing redirect in proj file. See if that thing works?
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:
c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\commonextensions\microsoft\fsharp\fsc.exe -o:obj\Release\netcoreapp2.2\myproject.dl [...]
dotnet build seems to execute:
C:\Program Files\dotnet\dotnet.exe "C:\Program Files\dotnet\sdk\2.2.300\FSharp\fsc.exe" -o:obj\release\netcoreapp2.2\myproject.dll [...]
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 of dotnet build may present a workaround.
@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.
I'm having the same issue with dotnet cli. I'll see if I can make progress with one of the suggestions above
Same issue, I'll try to use redirections to fix it. Will update on whether it works or not
Having the same issue, using Paket. Builds fine in Visual Studio, but not using dotnet build (from fake). Tried redirects: force on System.Data.SqlClient and SQLProvider 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.
I also have the same issue. Has anyone found a solution?
No, I couldn't make it work. In the end I changed the project to Typescript+Node.js. Anyone was able to fix it?
On Thu, Aug 29, 2019, 16:25 Samuel [email protected] wrote:
I also have the same issue. Has anyone found a solution?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fsprojects/SQLProvider/issues/626?email_source=notifications&email_token=AH3JCKC6PZO36VIGIRWOO6LQHA5FPA5CNFSM4H5FYEQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5P37NY#issuecomment-526368695, or mute the thread https://github.com/notifications/unsubscribe-auth/AH3JCKAUSCESOHR65FV2G6TQHA5FPANCNFSM4H5FYEQQ .
@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?
@schauerte what would be the msbuild workaround? I never found a workaround for this issue
@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).
@schauerte thanks. The workaround is good enough for me right now.
@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!
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:
C:\Users\username\Documents\Projects\ProjectName\ProjectName.FS.Lib\Db\DbLib.fs(10,16): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not load file or assembly 'System.Data.SqlClient, Version=4.6.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. [C:\Users\username\Documents\Projects\ProjectName\ProjectName.FS.Lib\ProjectName.FS.Lib.fsproj]
Since I'm using Azure DevOps for ~~CLI~~ CI, I do have MSBuild available, but it's unfortunate that I can't build via command-line on my own system to test things like dotnet publish instead of just building.