F# compilation error in Linqpad 7 when trying to use FSharp.Data packages
Hi,
On my computer I have .Net SDK 3.1 & .Net SDK 5.0. I am using Windows 2016. Linqpad version: 7.1.5. Other info:
Host runtime version: 5.0.12
Default query runtime version: 5.0.12
Default query reference assembly version: 5.0.0
Roslyn Version: 4.0.1-1.21558.15
FSharp.Compiler.Service version: 41.0.1.0
NuGet client version: 5.11.0.10
Results rendering engine: Microsoft WebBrowser 11
I created a new query with type F# Program:
<Query Kind="FSharpProgram"> <NuGetReference>FSharp.Data.SqlClient</NuGetReference> <Namespace>FSharp.Data.SqlClient</Namespace> </Query> [<Literal>] let compileTimeCn = @"Data Source=MyServer;Initial Catalog=MyDb;Integrated Security=True" use cmd = new SqlCommandProvider<"SELECT * from dbo.SomeTable" , compileTimeCn>(compileTimeCn) let data = cmd.Execute()
When I compile this I get:
The type provider 'C:\Users\xyz\.nuget\packages\FSharp.Data.SqlClient\2.0.7\lib\netstandard2.0\FSharp.Data.SqlClient.dll' reported an error: The type provider designer assembly 'FSharp.Data.SqlClient.DesignTime.dll' could not be loaded from folder 'C:\Users\xyz\.nuget\packages\FSharp.Data.SqlClient\2.0.7\lib\typeproviders\fsharp41\netstandard2.0'. The exception reported was: System.IO.FileNotFoundException - Could not load file or assembly 'FSharp.Core, Version=4.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
I also got a similar error when I tried to add the FSharp.Data package to read CSV files:The type provider 'C:\Users\xyz\.nuget\packages\FSharp.Data\4.2.6\lib\netstandard2.0\FSharp.Data.dll' reported an error: The type provider designer assembly 'FSharp.Data.DesignTime' could not be loaded from folder 'C:\Users\xyz\.nuget\packages\FSharp.Data\4.2.6\typeproviders\fsharp41\netstandard2.0'. The exception reported was: System.IO.FileNotFoundException - Could not load file or assembly 'FSharp.Core, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Any idea on how to fix this? Linqpad seems to have a problem with the F# type providers.
As a side note, in VS2019 I don't have these issues.
Thanks
Comments
In Linqpad 6 I get a different error:
The type provider 'FSharp.Data.SqlCommandProvider' reported an error: Could not load file or assembly 'System.Data.SqlClient, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
I added the reference to System.Data.SqlClient but it still gives the above error. So, I am not too sure what's going on here.
Have you tried the latest LINQPad 7 beta?
https://www.linqpad.net/linqpad7.aspx#beta
I am still getting an error in the beta version.
The type provider 'FSharp.Data.SqlCommandProvider' reported an error: Could not load file or assembly 'System.Data.SqlClient, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
Looks like it could be this issue:
https://github.com/fsprojects/FSharp.Data.SqlClient/issues/373
Fundamentally, it's a difficult problem to solve in .NET Core. Without application domains, resolving and loading arbitrary assemblies into the host (and unloading them again) is inherently hacky and unreliable.