Skip to content

Error when compiling on console #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
imetallica opened this issue Jul 3, 2019 · 14 comments
Open

Error when compiling on console #626

imetallica opened this issue Jul 3, 2019 · 14 comments
Labels
.NET Core reference assembly loading Not a bug, but a question about usability with .NET Core. Right dlls are not in ResolutionPath.

Comments

@imetallica
Copy link

imetallica commented Jul 3, 2019

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
@kunjee17
Copy link

kunjee17 commented Jul 3, 2019

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

@schauerte
Copy link

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
Copy link

@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
Copy link

allumbra commented 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
Copy link

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

@tempestCognitor
Copy link

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
Copy link

samme78 commented Aug 29, 2019

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

@isthistechsupport
Copy link

isthistechsupport commented Aug 29, 2019 via email

@schauerte
Copy link

@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
Copy link

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

@schauerte
Copy link

@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
Copy link

samme78 commented Aug 30, 2019

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

@isthistechsupport
Copy link

@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
Copy link

replicaJunction commented 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:

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.

@Thorium Thorium added the .NET Core reference assembly loading Not a bug, but a question about usability with .NET Core. Right dlls are not in ResolutionPath. label Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Core reference assembly loading Not a bug, but a question about usability with .NET Core. Right dlls are not in ResolutionPath.
Projects
None yet
Development

No branches or pull requests

9 participants