System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll' In very specific scenario
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 69
Description
### Describe the bug
Legacy WebService.asmx running under .Net Framework 4.6.2 with physical path configured in IIS to **network share** (not reproduced with local folder. Not reproduced with console app.)
Starting from version 2.x it is crashes with message System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll'
In 1.1 version of [SNINativeMethodWrapper.cs](https://github.com/dotnet/SqlClient/blob/1.1-servicing/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Interop/SNINativeMethodWrapper.cs) in static .ctor LoadLibrary was executed with correct path. In version 2.1 there is no call to LoadLibrary.
```
Exception message:
System.DllNotFoundException
HResult=0x80131524
Message=Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source=Microsoft.Data.SqlClient
StackTrace:
at Microsoft.Data.SqlClient.SNINativeManagedWrapperX64.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
at Microsoft.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token)
at Microsoft.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent()
at Microsoft.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory)
at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup)
at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
```
### To reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
```c#
[System.Web.Services.WebService(Namespace:="http://tempuri.org//MyService")]
Public Class MyService: System.Web.Services.WebService
[WebMethod()]
public string foo()
{
var connection = new Microsoft.Data.SqlClient.SqlConnection(connectionString);
connection.Open();
var command = connection.CreateCommand();
command.CommandText = "select 5";
return command.ExecuteScalar()?.ToString();
}
```
### Expected behavior
No exception is thrown. Connection to DB is working.
### Further technical details
Microsoft.Data.SqlClient version: 2.1.3
Microsoft.Data.SqlClient.SNI version: 2.1.1
.NET target: Framework 4.6.2
SQL Server version: SQL Server 2019
Operating system: Windows 10
**Additional context**
Add any other context about the problem here.
Contributor guide
Assessment
This issue has not been assessed yet.