Zaid-Ajaj / DustyTables

Thin F# API for SqlClient for easy data access to ms sql server with functional seasoning on top
MIT License
74 stars 11 forks source link

Cannot run on dotnet in the FSI #12

Open halcwb opened 4 years ago

halcwb commented 4 years ago

Describe the bug When trying to use the library I in thet FSI I get:

Binding session to 'C:\Users\cbollen.nuget\packages\microsoft.data.sqlclient\2.0.0\lib\netstandard2.0\Microsoft.Data.SqlClient.dll'... Real: 00:00:00.083, CPU: 00:00:00.015, GC gen0: 0, gen1: 0, gen2: 0 [] val it : Result<string list,exn> = Error System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform. at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString) in H:\tsaagent2_work\11\s\artifacts\Project\obj\Release.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.0\Microsoft.Data.SqlClient.notsupported.cs:line 318 at DustyTables.SqlModule.getConnection(SqlProps props) at DustyTables.SqlModule.execute[t](FSharpFunc2 read, SqlProps props) {Data = dict []; HResult = -2146233031; HelpLink = null; InnerException = null; Message = "Microsoft.Data.SqlClient is not supported on this platform."; Source = "Microsoft.Data.SqlClient"; StackTrace = " at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString) in H:\tsaagent2\_work\11\s\artifacts\Project\obj\Release.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.0\Microsoft.Data.SqlClient.notsupported.cs:line 318 at DustyTables.SqlModule.getConnection(SqlProps props) at DustyTables.SqlModule.execute[t](FSharpFunc2 read, SqlProps props)"; TargetSite = Void .ctor(System.String);}

When targetting netcoreapp3.1 I get:

Binding session to 'C:\Users\cbollen.nuget\packages\microsoft.data.sqlclient\2.0.0\lib\netcoreapp3.1\Microsoft.Data.SqlClient.dll'... Binding session to 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.dll'...

System.TypeLoadException: Could not load type 'System.ICloneable' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. at DustyTables.SqlModule.connect(String constr) at FSI_0003.executeGetLatest() in D:\Development\Informedica\apps\GenPed\src\Server\Scripts\Database.fsx:line 79 at <StartupCode$FSI_0004>.$FSI_0004.main@() Stopped due to error

To Reproduce Steps to reproduce the behavior:

  1. Add the dependency
  2. Target dotnet 2 or higher
  3. Load the Dusty Table libraries in the FSI
  4. Try to use them

Expected behavior Should be able to run on dotnet in the FSI

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information): NA

Smartphone (please complete the following information): NA

Additional context .NET Core SDK (reflecting any global.json): Version: 3.1.301 Commit: 7feb845744

Runtime Environment: OS Name: Windows OS Version: 6.1.7601 OS Platform: Windows RID: win7-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.301\

Host (useful for support): Version: 3.1.5 Commit: 65cd789777

.NET Core SDKs installed: 2.1.701 [C:\Program Files\dotnet\sdk] 2.1.801 [C:\Program Files\dotnet\sdk] 2.2.301 [C:\Program Files\dotnet\sdk] 2.2.401 [C:\Program Files\dotnet\sdk] 3.1.100 [C:\Program Files\dotnet\sdk] 3.1.101 [C:\Program Files\dotnet\sdk] 3.1.301 [C:\Program Files\dotnet\sdk]

Zaid-Ajaj commented 4 years ago

Hi Casper,

I just published a new version v2.2 targeted at netcoreapp3.1 and updated SqlClient dependency. I think it should work, please try it out and let me know how it goes.

halcwb commented 4 years ago

@Zaid-Ajaj. Thanks for your quick action!! But know I get a:

error FS0193: internal error: Could not load type 'System.Threading.CancellationToken' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Zaid-Ajaj commented 4 years ago

Sounds more like a FSI issue, I don't think there is something I can do about from this repo itself

halcwb commented 4 years ago

I don't think it's a FSI issue, I think it's a Zaid - paket issue ;-).

This is you're paket lock:

Microsoft.Data.SqlClient (1.1)

This you'r reference in the fsproj file:

    <ItemGroup>
        <PackageReference Include="Microsoft.Data.SqlClient" Version="2.0.0" />
    </ItemGroup>

So, when I use paket to generate my load scripts, I get the Microsoft.Data.SqlClient version 1.1, not the new 2.0.0 version.

I have cloned your repository. And changed to paket. When I then use the generate load scripts I have to use the generated scripts for a .net framework, for example net472. Otherwise, I cannot run the script.

So, I think what DustyTables actually compiles to is a .net framework dll, not a dotnet dll and you'l not be able to use this on a purely dotnet based environment.

Zaid-Ajaj commented 4 years ago

This is you're paket lock ... This you'r reference in the fsproj file

The project itself doesn't use Paket anymore (see there are no paket.references file nor the project is using paket imports) so it is fully nuget based. Only the FAKE build script uses paket.

So, I think what DustyTables actually compiles to is a .net framework dll, not a dotnet dll and you'l not be able to use this on a purely dotnet based environment

Nope, the latest version is strictly targeting netstandard2.0 and netcoreapp3.1 there is no .NET Framework reference in there and the correct version of the dependency Microsoft.Data.SqlClient (v2.0) is published to nuget as well:

2020-07-11 19_46_47-NuGet Gallery _ DustyTables 2 2 0

halcwb commented 4 years ago

Well this is quite a rabbit hole for me. I still am stuck in the fsi and raised an issue: https://github.com/dotnet/SqlClient/issues/645.

I will keep you posted, but not being able to use DustyTables in the fsi is a bit of a showstopper for me. Did you ever try, or succeed doing this?

halcwb commented 3 years ago

@Zaid-Ajaj : I still am struggling getting DustyTables to run in a script file. Did you ever try that?

Zaid-Ajaj commented 3 years ago

Hi Casper, sorry I haven't been able to debug why DustyTables isn't working in FSI, I don't think it is a library problem but will resume the investigation into the issue soon. It has been a very busy period, sorry for the delayed answers. Let's have a chat soon, I would love to hear about the latest projects you have been building and you have my number 😉

Looking at the issue you referenced, it seems that the last comment there is by someone who was able to fix the problem at hand but the fix isn't included in the library so I think we can wait until one of the maintainers implement the fix. You can also try with the dotnet 5 sdk to see if that fixes the problem, I haven't tried that yet on my machine. Last thing I can try is bump the SqlClient dependency from 2.0 to 2.1 and see if that fixes the problem.

I will try a couple of things and keep you posted!

halcwb commented 3 years ago

@Zaid-Ajaj Great, thanks. Well, I don't actually have your number (only you're Skype) ;-). But you have mine, it's in my email signature. So, please call me, there are a lot of things going on.

With regard to the problem, you're right, this is a more fundamental issue with referencing libraries in FSI. This is a common issue where you see: could not load type from assembly. In the case of using Microsoft.Data.SqlClient, you keep getting:

System.Threading.CancellationToken' from assembly 'System.Runtime, Version=4.0.0.0,

While I do reference the newer System.Runtime: // #r "C:\Users\\.nuget\packages\system.runtime\4.3.1\lib\net462\System.Runtime.dll"

Still the old version 4.0.0.0 is used from the GAC.