SqlClient: Cannot use with F# scripts
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. - After looking around for a while, read this link.
- 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.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 37 (13 by maintainers)
You’re going to have the same problems on netcore. The library is no longer in-box and has external dependencies which are resolved by nuget. You need either a nuget package restore or to manually walk the dependency tree and ensure all required dependencies are present.
Try the managed appcontext switch as @cheenamalhotra suggested, that removes the native dll requirement.
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.
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 thoguhI still get this same error with the
#r "nuget:..."
feature with F# scripts. This feature does load native .dlls (such as those in ML.NET), so there might be something else missing? @isaacabraham can you confirm this if you run the following?(replacing whatever query is there with your own)
I get
@cheenamalhotra perhaps open this again?