Skip to content
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

Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll' #645

Closed
halcwb opened this issue Jul 11, 2020 · 14 comments
Closed

Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll' #645

halcwb opened this issue Jul 11, 2020 · 14 comments

Comments

@halcwb
Copy link

halcwb commented Jul 11, 2020

Describe the bug

A clear and concise description of what the bug is.

I am trying to use the SqlClient (version 2.0.0) in an F# fsi environment. I can load the lib using the following load script:

#r "C:\\Users\\me\\.nuget\\packages\\microsoft.data.sqlclient\\2.0.0\\lib\\net46\\Microsoft.Data.SqlClient.dll" 
#r "C:\\Users\\me\\.nuget\\packages\\fsharp.data\\3.3.3\\lib\\net45\\FSharp.Data.dll" 
#r "C:\\Users\\me\\.nuget\\packages\\microsoft.identity.client\\4.16.1\\lib\\net45\\Microsoft.Identity.Client.dll" 
#r "C:\\Users\\me\\.nuget\\packages\\microsoft.identitymodel.logging\\6.7.1\\lib\\net45\\Microsoft.IdentityModel.Logging.dll" 
#r "C:\\Users\\me\\.nuget\\packages\\microsoft.identitymodel.tokens\\6.7.1\\lib\\net45\\Microsoft.IdentityModel.Tokens.dll" 
#r "C:\\Users\\me\\.nuget\\packages\\microsoft.identitymodel.jsonwebtokens\\6.7.1\\lib\\net45\\Microsoft.IdentityModel.JsonWebTokens.dll" 
#r "C:\\Users\\me\\.nuget\\packages\\microsoft.identitymodel.protocols\\6.7.1\\lib\\net45\\Microsoft.IdentityModel.Protocols.dll" 
#r "C:\\Users\\me\\.nuget\\packages\\system.identitymodel.tokens.jwt\\6.7.1\\lib\\net45\\System.IdentityModel.Tokens.Jwt.dll" 
#r "C:\\Users\\me\\.nuget\\packages\\microsoft.identitymodel.protocols.openidconnect\\6.7.1\\lib\\net45\\Microsoft.IdentityModel.Protocols.OpenIdConnect.dll" 
#r "Microsoft.CSharp" 
#r "System" 
#r "System.Core" 
#r "System.Data" 
#r "System.Data.DataSetExtensions" 
#r "System.Drawing" 
#r "System.IdentityModel" 
#r "System.Net.Http" 
#r "System.Windows.Forms" 
#r "System.Xml" 
#r "System.Xml.Linq" 

However, when I try to use the client than I get the following error:

Exception message:
Stack trace:
[<Struct>]
val it : Result<string option list,exn> =
  Error
    System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll': Kan opgegeven module niet vinden. (Exception from HRESULT: 0x8007007E)
   at Microsoft.Data.SqlClient.SNINativeManagedWrapperX86.SNIInitialize(IntPtr pmo)
   at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\Interop\SNINativeMethodWrapper.cs:line 589
   at Microsoft.Data.SqlClient.SNILoadHandle..ctor() in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:line 30
   at Microsoft.Data.SqlClient.SNILoadHandle..cctor() in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:line 17
   --- End of inner exception stack trace ---
   at Microsoft.Data.SqlClient.TdsParser..cctor() in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:line 177
   --- End of inner exception stack trace ---
   at Microsoft.Data.SqlClient.TdsParser..ctor(Boolean MARS, Boolean fAsynchronous) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:line 38
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:line 1796
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:line 1685
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, ServerCertificateValidationCallback serverCallback, ClientCertificateRetrievalCallback clientCallback, DbConnectionPool pool, String accessToken, SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo, Boolean applyTransientFaultHandling) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:line 525
   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnectionFactory.cs:line 143
   at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:line 163
   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 943
   at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 2000
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 1412
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 1296
   at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:line 354
   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionInternal.cs:line 766
   at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionClosed.cs:line 71
   at Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1946
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1934
   at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1495
   at Microsoft.Data.SqlClient.SqlConnection.Open() in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1466
   at FSI_0009.Lib.SqlModule.execute[t](FSharpFunc`2 read, SqlProps props) in D:\Development\Informedica\apps\GenPed\src\Lib\Sql.fs:line 222
      {Data = dict [];
       HResult = -2146233036;
       HelpLink = null;
       InnerException = System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll': Kan opgegeven module niet vinden. (Exception from HRESULT: 0x8007007E)
   at Microsoft.Data.SqlClient.SNINativeManagedWrapperX86.SNIInitialize(IntPtr pmo)
   at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\Interop\SNINativeMethodWrapper.cs:line 589
   at Microsoft.Data.SqlClient.SNILoadHandle..ctor() in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:line 30
   at Microsoft.Data.SqlClient.SNILoadHandle..cctor() in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:line 17
   --- End of inner exception stack trace ---
   at Microsoft.Data.SqlClient.TdsParser..cctor() in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:line 177;
       Message = "The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception.";
       Source = "Microsoft.Data.SqlClient";
       StackTrace = "   at Microsoft.Data.SqlClient.TdsParser..ctor(Boolean MARS, Boolean fAsynchronous) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:line 38
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:line 1796
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:line 1685
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, ServerCertificateValidationCallback serverCallback, ClientCertificateRetrievalCallback clientCallback, DbConnectionPool pool, String accessToken, SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo, Boolean applyTransientFaultHandling) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:line 525
   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnectionFactory.cs:line 143
   at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:line 163
   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 943
   at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 2000
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 1412
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 1296
   at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:line 354
   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionInternal.cs:line 766
   at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionClosed.cs:line 71
   at Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1946
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1934
   at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides) in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1495
   at Microsoft.Data.SqlClient.SqlConnection.Open() in H:\tsaagent2\_work\11\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1466
   at FSI_0009.Lib.SqlModule.execute[t](FSharpFunc`2 read, SqlProps props) in D:\Development\Informedica\apps\GenPed\src\Lib\Sql.fs:line 222";
       TargetSite = Void .ctor(Boolean, Boolean);
       TypeName = "Microsoft.Data.SqlClient.TdsParser";}

To reproduce

Trying to use the client by any code causes the issue. It seems that the required NSI lib is not referenced/loaded. When I try to reference the lib manually I get a bad cli header

Expected behavior

That the nsi lib is found.

Further technical details

.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]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@halcwb
Copy link
Author

halcwb commented Jul 11, 2020

I also tried the recommendations in: #292. However, with no luck. Finally I compiled the project referencing the Microsoft.Data.SqlClient and referenced the dll from the bin folder (that had the NSI dlls inside as well) and only then I got it to run in the FSI.

But I am still not sure how you can use the SqlClient in a standalone fsx script file.

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 12, 2020

Did you try the AppContext switch?

@halcwb
Copy link
Author

halcwb commented Jul 13, 2020

@ErikEJ I did that, with no luck. When I build targeted at net46, net472,netstandard2.0 and netstandard2.1, the bin folders for the net versions contain all dependency files. The bin folder for netstandard only contains the proj dll??

@karinazhou
Copy link
Member

Hi @halcwb,

From the repro description, I assume that your application is targeting .net framework. On Windows, the driver depends on another standalone nuget package Microsoft.Data.SqlClient.SNI which contains the native SNI.dll.

According to #292 , you need to reference individual dlls manually if you are using F# scripts. If you only have Microsoft.Data.SqlClient.dll, this will not work as expected. Can you also add Microsoft.Data.SqlClient.SNI.x86.dll from your NuGet package cache to your load script and try with that?
C:\Users\karinaz\.nuget\packages\microsoft.data.sqlclient.sni\2.0.0\build\net46\Microsoft.Data.SqlClient.SNI.x86.dll

For .net standard and .net core app on Windows, try to add
C:\Users\karinaz\.nuget\packages\microsoft.data.sqlclient.sni.runtime\2.0.0\runtimes\win-x86\native\Microsoft.Data.SqlClient.SNI.dll

And please always use dlls from \runtimes instead of \lib for Microsoft.Data.SqlClient.dll such as
C:\Users\karinaz\.nuget\packages\microsoft.data.sqlclient\2.0.0\runtimes\win\lib\net46\Microsoft.Data.SqlClient.dll
C:\Users\karinaz\.nuget\packages\microsoft.data.sqlclient\2.0.0\runtimes\win\lib\netcoreapp2.1\Microsoft.Data.SqlClient.dll

@cheenamalhotra cheenamalhotra added this to Needs triage in SqlClient Triage Board via automation Jul 15, 2020
@cheenamalhotra cheenamalhotra moved this from Needs triage to Waiting for customer in SqlClient Triage Board Jul 15, 2020
@halcwb
Copy link
Author

halcwb commented Jul 15, 2020

@karinazhou As I previously wrote, I followed all the instructions as mentioned in #292. I suspect that the SNI dll needs to be in the same directory as the SqlClient? It only works by compiling the project using the SqlClient and then referencing from the bin folder like:

#r "../bin/Release/net472/Microsoft.Data.SqlClient.dll"

@karinazhou
Copy link
Member

karinazhou commented Jul 15, 2020

@halcwb For .net framework application, yes, the SqlClient will search the same directory for the SNI.dll if required during runtime. For .net core application on Windows, this is also true if you don't specify the following AppContext.SetSwitch in your application:

AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", true);

If you have this AppContext.SetSwitch in your .net core application, the SqlClient won't rely on SNI.dll.

On Linux / Mac, SNI.dll is not required.

@halcwb
Copy link
Author

halcwb commented Jul 16, 2020

@karinazhou I tried the AppContext.SetSwitch. That didn't work. Also, when I build the project with only netstandard as framework target, I only get the project dll, not the rest of the dependencies dll's.

When I then tried to use the project dll I get:

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' or one of its dependencies. Het systeem kan het opgegeven bestand niet vinden.
File name: 'Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'

Update:
I finally got it running, with the following:

  1. I use paket as package manager
  2. I use paket generate-load-scripts to generate the load scripts that load all dependencies dll's
  3. I then have to manually change the reference to the client dll in the load script to the runtimes/win folder
  4. I also need to set the AppContext.SetSwitch

Then I can use the Microsoft.Data.Client in a script file and the fsi.

Thanks for helping out.

@cheenamalhotra
Copy link
Member

Closing issue as resolved.

SqlClient Triage Board automation moved this from Waiting for customer to Closed Jul 17, 2020
@aggieben
Copy link

aggieben commented Jul 24, 2020

@cheenamalhotra I don't think this issue should be closed as resolved. The approach above is a workaround, not a solution.

@cheenamalhotra
Copy link
Member

Reopening issue to validate Native SNI to work with F# on Windows.

SqlClient Triage Board automation moved this from Closed to Needs triage Jul 31, 2020
@OpenSpacesAndPlaces
Copy link

@halcwb

I suspect that the SNI dll needs to be in the same directory as the SqlClient?

That fixes it. I copied the native SNI files from the Nuget folder directly to bin and all was well.

@halcwb
Copy link
Author

halcwb commented Jan 21, 2021

I used a different approach:

  1. I have a net5 lib
  2. I have added a nuget reference to Microsoft.Data.SqlClient
  3. I have some simple code in a project
  4. I use dotnet publish <PATH TO PROJ> -f net5.0 -o <PATH TO OUTPUT> to put all dlls in one folder
  5. I then still need to manually copy the runtime Microsoft.Data.SqlClient.dll to the output folder

I can then reference the manually copied dll and use the FSI with VSCode. In VS, somehow a netframework runtime is used. Using the context switch doesn't do a thing as far as I can tell.

For example, I can use this code in the FSI:

#r @"../bin/publish/Microsoft.Data.SqlClient.dll"

open System

open Microsoft.Data.SqlClient

let builder  = SqlConnectionStringBuilder()
builder.UserID <- "halcwb"

builder.ConnectionString

NOTE
Just using r: nuget Microsoft.Data.SqlClient" also works in VSCode.

@halcwb halcwb closed this as completed Jan 21, 2021
SqlClient Triage Board automation moved this from Needs triage to Closed Jan 21, 2021
@OpenSpacesAndPlaces
Copy link

@cheenamalhotra Looks like this got auto-closed again.
Unless there was a patch not mentioned in the thread - workarounds are still the only option.

@tomarikawa
Copy link

Is there a fix (instead of a workaround) for this available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

7 participants