Skip to content

Error when compiling on console #626

Open
@imetallica

Description

@imetallica

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

  1. dotnet new console -lang F#

  2. dotnet add package SQLProvider

  3. 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>
  1. 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

kunjee17 commented on Jul 3, 2019

@kunjee17

@imetallica can you give it a try with Paket or forcing redirect in proj file. See if that thing works?

schauerte

schauerte commented on Jul 16, 2019

@schauerte

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.

kunjee17

kunjee17 commented on Jul 16, 2019

@kunjee17

@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

allumbra commented on Aug 8, 2019

@allumbra

I'm having the same issue with dotnet cli. I'll see if I can make progress with one of the suggestions above

isthistechsupport

isthistechsupport commented on Aug 8, 2019

@isthistechsupport

Same issue, I'll try to use redirections to fix it. Will update on whether it works or not

tempestCognitor

tempestCognitor commented on Aug 9, 2019

@tempestCognitor

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.

samme78

samme78 commented on Aug 29, 2019

@samme78

I also have the same issue. Has anyone found a solution?

isthistechsupport

isthistechsupport commented on Aug 29, 2019

@isthistechsupport
schauerte

schauerte commented on Aug 30, 2019

@schauerte

@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

isthistechsupport commented on Aug 30, 2019

@isthistechsupport

@schauerte what would be the msbuild workaround? I never found a workaround for this issue

schauerte

schauerte commented on Aug 30, 2019

@schauerte

@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

samme78 commented on Aug 30, 2019

@samme78

@schauerte thanks. The workaround is good enough for me right now.

isthistechsupport

isthistechsupport commented on Aug 31, 2019

@isthistechsupport

@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

replicaJunction commented on Nov 8, 2019

@replicaJunction

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.

added
.NET Core reference assembly loadingNot a bug, but a question about usability with .NET Core. Right dlls are not in ResolutionPath.
on Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NET Core reference assembly loadingNot a bug, but a question about usability with .NET Core. Right dlls are not in ResolutionPath.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Error when compiling on console · Issue #626 · fsprojects/SQLProvider