Repository navigation
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 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.
[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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog
Activity
David-Engel commentedon Jul 2, 2021
@myurashchyk From 1.x to 2.x, the dependency of SNI native binaries changed from the same filename being stored in subfolders (x64 and x86) relative to Microsoft.Data.SqlClient.dll to different filenames (Microsoft.Data.SqlClient.SNI.x64.dll and Microsoft.Data.SqlClient.SNI.x86.dll) stored in the same folder as Microsoft.Data.SqlClient.dll. Does your deployment have the new file structure? Did you verify that the files are actually deployed there for SqlClient to load?
I'm just wondering if this is a deployment issue, or an issue actually loading the DLLs from a network share.
fvasquezc23 commentedon Aug 26, 2021
I have the same issue running the application on a network share.
Microsoft.Data.SqlClient.SNI.X64.dll is copied to bin, works locally but fails on network share.
Windows Server 2016
IIS .NET framework 4.7.2
Microsoft.Data.SqlClient 2.1.3
Microsoft.Data.SqlClient.SNI 2.1.1
RustinAlexandru commentedon Aug 22, 2023
Exactly the same issue as above.
It works locally, it works when deployed but running from the disk, doesn't work when running on a network share, dll is not loaded.
David-Engel commentedon Aug 22, 2023
@RustinAlexandru
You might be trying to cross a trust boundary. If you are on .NET Framework, this app.config setting might help your app run from a network share:
https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/loadfromremotesources-element
RustinAlexandru commentedon Aug 23, 2023
Thank you for the suggestion, tried that, but no luck, still getting the error.
System.DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Microsoft.Data.SqlClient.SNINativeManagedWrapperX64.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
at Microsoft.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token) in D:\a_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\Interop\SNINativeMethodWrapper.cs:line 1442
at Microsoft.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent() in D:\a_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.cs:line 115
LE: Sorry, forgot the add the configuration:
Windows Server 2016 Standard
IIS .NET framework 4.8
Microsoft.Data.SqlClient version="5.1.1"
Microsoft.Data.SqlClient.SNI version="5.1.1"
Any other ideas we could be trying?
RustinAlexandru commentedon Aug 23, 2023
For anyone else, having this issue, one workaround we did is just load the SNI dll ourselves, something like this:
Not great, but gets the job done, hopefully this issue gets some attention and will be fixed in later versions.
priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
🔍 Triage Summary (on-demand re-triage)
Area\Native SNIAnalysis
This issue reports a
System.DllNotFoundExceptionforMicrosoft.Data.SqlClient.SNI.x64.dllthat occurs only when the application (an ASP.NET WebService under .NET Framework 4.6.2, later confirmed by multiple other reporters under IIS/.NET 4.7.2/4.8) is deployed to and executed from a network share, not a local disk. The reporter identified that in v1.1,SNINativeMethodWrapper's static constructor explicitly calledLoadLibrarywith the correct path, but this call was removed starting in v2.x, relying instead on the default OS DLL search/probing behavior, which does not reliably resolve native DLLs when the managed assembly itself is loaded from a UNC/network path (a partial-trust /LoadFromRemoteSourcesboundary issue on .NET Framework). Multiple independent reporters over several years (2021–2023) confirm the same root cause across different SqlClient versions (2.1.3, 5.1.1) and .NET Framework versions, and a community workaround of manually callingLoadLibraryon the SNI DLL resolves it. Given the multi-year recurrence and existing parent tracking issue#4129"SNI loading issues", this should be prioritized as P2 — a real regression affecting a valid (if less common) deployment topology, but with a known workaround.Next Steps
LoadLibrarycall (with the correct assembly-relative path) in the native SNI loading path for .NET Framework (netfx), similar to the pre-2.x behavior inSNINativeMethodWrapper.cs, so that native DLL resolution works correctly when the managed assembly is loaded from a UNC/network share path rather than relying solely on default OS DLL probing.LoadLibrarycall is recommended to confirm root cause before implementing a fix.