You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scripts are a common and everyday way to work F# and forms part of the standard development lifecycle. I can't figure out how to use the SqlClient library from within an F# script:
Download the nuget package.
Try referencing the netstandard version of the library e.g. #r @"C:\Users\Isaac\.nuget\packages\microsoft.data.sqlclient\1.0.19269.1\lib\netstandard2.0\Microsoft.Data.SqlClient.dll.
Script will crash when you try to open a connection with a PlatformNotSupported exception.
Try to reference the net46 version of the library: #r @"C:\Users\Isaac\.nuget\packages\microsoft.data.sqlclient\1.0.19269.1\lib\net46\Microsoft.Data.SqlClient.dll"
Get another exception:
System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception. ---> System.ComponentModel.Win32Exception: Failed to load C:\Users\Isaac\.nuget\packages\microsoft.data.sqlclient\1.0.19269.1\lib\net46\x64\SNI.dll
at Microsoft.Data.SqlClient.SNINativeMethodWrapper..cctor() in E:\agent1\_work\34\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\Interop\SNINativeMethodWrapper.cs:line 66
I can't find any SNI.dll within the nuget package. How can I get this to work?
Also - why include a netstandard2.0 TFM in the package, if netstandard2.0 is, effectively, not supported? This is misleading and very tightly couples the package to NuGet.
Netstandard is supported but it requires a target platform to be resolved in order to restore the correct windows or unix native socket implementation. I think what you're really asking is why there is no fully portable fallback.
Note that SNI.dll on windows isn't the only dependency that is required. You'll also need codepage support and a number of other things like configuration. SqlClient was in-box before and could be used easily because it only had framework dependencies. This library isn't in-box and has external dependencies, they're not really equivalent.
@Wraith2 thanks, that helps to understand it better. Is there a list of these required dependencies anywhere - and if they are not shipped with the nuget package, where are they? Thanks again
Is there a list of these required dependencies anywhere - and if they are not shipped with the nuget package, where are they?
The NuGet package contains the details of all the dependencies and the NuGet infrastructure facilitates the downloading and referencing of them all. You can view them in the .nuspec file contained inside the package or on the Nuget website. You will have to fully resolve the dependency tree yourself if you choose not to use the NuGet infrastructure. What you are trying to do is very similar to what this PowerShell developer wanted to do in #161.
@Wraith2 thanks, I will look at that. Note: this is not a matter of choice - NuGet has no support for F# scripts, it only works with applications (.NET exes, libraries) so I have no choice but to go alone here; in the last 5+ years of working with F# this is the first nuget package I've come across that has this issue.
Note also : I have all the dependencies downloaded - it's simply a matter of understanding within the package what things need to be resolved and in what order. This is something I'm not sure is readily visible.
I can't find any SNI.dll within the nuget package. How can I get this to work?
Please verify the version of NuGet.exe in use is >5.0 when performing nuget restore. If using version >5.0, dependent DLLs (SNI.dll for x64 and x86) should be loaded transitively, look for #137 for more details.
Try referencing the netstandard version of the library e.g. #r @"C:\Users\Isaac.nuget\packages\microsoft.data.sqlclient\1.0.19269.1\lib\netstandard2.0\Microsoft.Data.SqlClient.dll
why include a netstandard2.0 TFM in the package, if netstandard2.0 is, effectively, not supported? This is misleading and very tightly couples the package to NuGet.
NetStandard 2.0 is supported, apparently the correct path to supported DLL is runtimes\<os>\lib\netstandard2.0\Microsoft.Data.SqlClient.dll and not lib\netstandard2.0\Microsoft.Data.SqlClient.dll.
@cheenamalhotra I'm trying to use an F# script, which NuGet doesn't support. We have to manually reference the individual assemblies in the packages to get things to work. Thanks for that link, I will look into it.
Either way, as it turns out known limitation from NuGet, I would like to close this issue at our end and suggest registering issues with NuGet and Visual Studio to support package reference for F# scripts.
@cheenamalhotra This is in an F# script. There is no msbuild. We just reference dlls manually. It's nothing to do with NuGet - I just need to know which DLLs to reference :-/
@David-Engel that's not until net5 - forget about that, it's a red herring :-) Currently we reference individual DLLs for scripts. It works very well and there's decent tooling around that as well. In this case it's not working because of the native dlls, so I need to add them manually. I just need to know what they are - is it really not possible to get a list of them?
Awesome, that does work. Is this going to be a default in .NET 5?
Separately, it seems like failing to find sni.dll is a bug in the dependency manager component used with FSI on .NET Core. We'll need to investigate thoguh
Awesome, that does work. Is this going to be a default in .NET 5?
This library is versioned independently from the runtime so it doesn't really matter. I think it's unlikely that the System.Data.SqlClient version that the runtime has will be updated with this switch, it was disabled for good reasons in the past and it's only recently that it's been made available to users again. In the long term I'd like to have managed mode be the default and not use the native dll at all but to do that performance and reliability need to be equal or better for everyone.
it seems like failing to find sni.dll is a bug in the dependency manager component used with FSI on .NET Core
If it is attempting to restore dependencies in a way compatible with nuget behaviour and you're getting this error then I'd agree that it's a problem that the FSI owners might want to take a look at.
System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.
at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString) in H:\tsaagent1\_work\9\s\obj\Release.AnyCPU\Microsoft.Data.SqlClient\netcore\netcoreapp3.1\Microsoft.Data.SqlClient.notsupported.cs:line 355
at <StartupCode$FSI_0010>.$FSI_0010.main@()
Stopped due to error
Please ensure you pick up "runtime" libraries from path:
#r "C:\Users\Isaac\.nuget\packages\microsoft.data.sqlclient\2.0.0-preview3.20122.2\runtimes\win\lib\netcoreapp3.1\Microsoft.Data.SqlClient.dll"
OR
#r "C:\Users\Isaac\.nuget\packages\microsoft.data.sqlclient\2.0.0-preview3.20122.2\runtimes\win\lib\netstandard2.0\Microsoft.Data.SqlClient.dll"
The DLLs in lib\netcoreapp2.1 and lib\netstandard2.0 are "Not Supported" DLLs.
@cartermp I'm not on net5. I've had some issues with it conflicting with picking up the wrong msbuild for some projects (even with explicit dotnet core refs) so I'm back to 3.x
@cheenamalhotra that worked! I had to still add in the dependent DLLs (system,configuration being the main one) but it then works. This is really important - being in a situation when F# scripts couldn't talk to a Microsoft SQL database using Microsoft's NuGet package was an awkward situation to be in.
@isaacabraham are you using FSI with #r "nuget"? I wouldn't recommend any other way to acquire dependencies for scripts at the moment.
I'm trying this with #r "nuget: Microsoft.Data.SqlClient, Version=2.0.0-*" on dotnet 3.1 and it results in this output:
System.PlatformNotSupportedException: Microsoft.Data.SqlClient is not supported on this platform.
at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString) in H:\tsaagent1_work\9\s\artifacts\Project\obj\Release.AnyCPU\Microsoft.Data.SqlClient\netcore\netcoreapp3.1\Microsoft.Data.SqlClient.notsupported.cs:line 355
at FSI_0003.getConnection()
at <StartupCode$FSI_0003>.$FSI_0003.main@()
Stopped due to error
System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
@cheenamalhotra I'm kinda doing that, although not exactly. I'm using .NET 5 preview, and --langversion:preview for FSI, and using the package like this (minimal example):
@cheenamalhotra yeah - so if I switch to Paket load scripts and manually adjust the path of the Microsoft.Data.SqlClient dll to the Windows one under ~/runtimes, it seems to work.
Hopefully an issue will remain open somewhere for this, because this should work out of the box.
Activity
Wraith2 commentedon Oct 30, 2019
Netstandard is supported but it requires a target platform to be resolved in order to restore the correct windows or unix native socket implementation. I think what you're really asking is why there is no fully portable fallback.
Note that SNI.dll on windows isn't the only dependency that is required. You'll also need codepage support and a number of other things like configuration. SqlClient was in-box before and could be used easily because it only had framework dependencies. This library isn't in-box and has external dependencies, they're not really equivalent.
isaacabraham commentedon Oct 30, 2019
@Wraith2 thanks, that helps to understand it better. Is there a list of these required dependencies anywhere - and if they are not shipped with the nuget package, where are they? Thanks again
David-Engel commentedon Oct 30, 2019
The NuGet package contains the details of all the dependencies and the NuGet infrastructure facilitates the downloading and referencing of them all. You can view them in the .nuspec file contained inside the package or on the Nuget website. You will have to fully resolve the dependency tree yourself if you choose not to use the NuGet infrastructure. What you are trying to do is very similar to what this PowerShell developer wanted to do in #161.
isaacabraham commentedon Oct 30, 2019
@Wraith2 thanks, I will look at that. Note: this is not a matter of choice - NuGet has no support for F# scripts, it only works with applications (.NET exes, libraries) so I have no choice but to go alone here; in the last 5+ years of working with F# this is the first nuget package I've come across that has this issue.
isaacabraham commentedon Oct 30, 2019
Note also : I have all the dependencies downloaded - it's simply a matter of understanding within the package what things need to be resolved and in what order. This is something I'm not sure is readily visible.
cheenamalhotra commentedon Nov 20, 2019
Hi @isaacabraham
Please verify the version of NuGet.exe in use is >5.0 when performing nuget restore. If using version >5.0, dependent DLLs (SNI.dll for x64 and x86) should be loaded transitively, look for #137 for more details.
NetStandard 2.0 is supported, apparently the correct path to supported DLL is
runtimes\<os>\lib\netstandard2.0\Microsoft.Data.SqlClient.dlland notlib\netstandard2.0\Microsoft.Data.SqlClient.dll.isaacabraham commentedon Nov 22, 2019
@cheenamalhotra I'm trying to use an F# script, which NuGet doesn't support. We have to manually reference the individual assemblies in the packages to get things to work. Thanks for that link, I will look into it.
cheenamalhotra commentedon Nov 22, 2019
I see. Looks like there is a workaround with
msbuild /t:restore, have you tried that? (NuGet/Home#7743 (comment))cheenamalhotra commentedon Nov 22, 2019
Either way, as it turns out known limitation from NuGet, I would like to close this issue at our end and suggest registering issues with NuGet and Visual Studio to support package reference for F# scripts.
isaacabraham commentedon Dec 3, 2019
@cheenamalhotra This is in an F# script. There is no msbuild. We just reference dlls manually. It's nothing to do with NuGet - I just need to know which DLLs to reference :-/
David-Engel commentedon Dec 3, 2019
It looks like nuget package support is something they recently merged over at fsharp: dotnet/fsharp#5850
https://twitter.com/realvictorprm/status/1173639408693723136?s=19
I don't know what their release schedule looks like or what release it is or will be in, but you can probably find more news over there.
isaacabraham commentedon Dec 9, 2019
@David-Engel that's not until net5 - forget about that, it's a red herring :-) Currently we reference individual DLLs for scripts. It works very well and there's decent tooling around that as well. In this case it's not working because of the native dlls, so I need to add them manually. I just need to know what they are - is it really not possible to get a list of them?
isaacabraham commentedon Dec 9, 2019
@cheenamalhotra perhaps open this again?
9 remaining items
Wraith2 commentedon May 6, 2020
Try the managed appcontext switch as @cheenamalhotra suggested, that removes the native dll requirement.
cartermp commentedon May 6, 2020
Awesome, that does work. Is this going to be a default in .NET 5?
Separately, it seems like failing to find
sni.dllis a bug in the dependency manager component used with FSI on .NET Core. We'll need to investigate thoguhWraith2 commentedon May 6, 2020
This library is versioned independently from the runtime so it doesn't really matter. I think it's unlikely that the System.Data.SqlClient version that the runtime has will be updated with this switch, it was disabled for good reasons in the past and it's only recently that it's been made available to users again. In the long term I'd like to have managed mode be the default and not use the native dll at all but to do that performance and reliability need to be equal or better for everyone.
If it is attempting to restore dependencies in a way compatible with nuget behaviour and you're getting this error then I'd agree that it's a problem that the FSI owners might want to take a look at.
isaacabraham commentedon May 21, 2020
Just a quick update - just trying this out and still got the same problem, but if it's working for @cartermp I must be doing something wrong now?
with error
Generated references:
This is on netcore3.1 running latest FSI.
cheenamalhotra commentedon May 21, 2020
Please ensure you pick up "runtime" libraries from path:
#r "C:\Users\Isaac\.nuget\packages\microsoft.data.sqlclient\2.0.0-preview3.20122.2\runtimes\win\lib\netcoreapp3.1\Microsoft.Data.SqlClient.dll"
OR
#r "C:\Users\Isaac\.nuget\packages\microsoft.data.sqlclient\2.0.0-preview3.20122.2\runtimes\win\lib\netstandard2.0\Microsoft.Data.SqlClient.dll"
The DLLs in lib\netcoreapp2.1 and lib\netstandard2.0 are "Not Supported" DLLs.
cartermp commentedon May 21, 2020
@isaacabraham are you using FSI with
#r "nuget"? I wouldn't recommend any other way to acquire dependencies for scripts at the moment.isaacabraham commentedon May 21, 2020
@cartermp I'm not on net5. I've had some issues with it conflicting with picking up the wrong msbuild for some projects (even with explicit dotnet core refs) so I'm back to 3.x
isaacabraham commentedon May 21, 2020
@cheenamalhotra thanks, I'll try that
isaacabraham commentedon May 23, 2020
@cheenamalhotra that worked! I had to still add in the dependent DLLs (system,configuration being the main one) but it then works. This is really important - being in a situation when F# scripts couldn't talk to a Microsoft SQL database using Microsoft's NuGet package was an awkward situation to be in.
Thanks for helping.
aggieben commentedon Jun 13, 2020
I'm trying this with
#r "nuget: Microsoft.Data.SqlClient, Version=2.0.0-*"on dotnet 3.1 and it results in this output:aggieben commentedon Jul 24, 2020
Tried again today with 2.0.0, and failed with
cheenamalhotra commentedon Jul 24, 2020
@aggieben
Could you try solution posted in #645 (comment) ?
aggieben commentedon Jul 24, 2020
@cheenamalhotra I'm kinda doing that, although not exactly. I'm using .NET 5 preview, and
--langversion:previewfor FSI, and using the package like this (minimal example):I'll give the other way a whirl and see if that helps.
aggieben commentedon Jul 24, 2020
@cheenamalhotra yeah - so if I switch to Paket load scripts and manually adjust the path of the
Microsoft.Data.SqlClientdll to the Windows one under~/runtimes, it seems to work.Hopefully an issue will remain open somewhere for this, because this should work out of the box.
isaacabraham commentedon Aug 18, 2020
I ended up writing up a minimal sample for a blog post here. I assume that for now this is the same in .NET 5 with hash R.