Skip to content

Microsoft.Data.SqlClient.SNI not deployed in "Website" projects #1955

Open

Description

@StephenMolloy

Describe the bug

In the old ASP.Net "Web Site" project, Microsoft.Data.SqlClient.SNI binaries are not being included in the 'bin' directory output. The nuget package is successfully added to packages.config when adding the Microsoft.DataSqlClient package... but the SNI binaries are not deployed.

I believe this is likely because the "Web Site" model - being "project-less" - does not play well with MSBuild. Visual Studio takes some steps to make a majority of Nuget packages work in this model. I don't know the exact mechanics of it, but iirc, either VS or nuget place a *.refresh file in the bin directory of the website for each binary in the 'lib' folder of the nuget package. The *.refresh file simply contains a path pointing to the original dll so VS can check for updates when building and deploy new or missing dll's in the build output. This is how Microsoft.Data.SqlClient.dll gets included.

But the SNI binaries aren't in the 'lib' folder. It seems they rely on a .targets file in the 'build' folder to copy them to build output. But "Website" projects aren't msbuild-based. So that targets file isn't ever looked at or run afaik.

To reproduce

  1. Install "Additional project templates..." under “ASP.Net and Web Development” section of Visual Studio Installer
  2. Create a "ASP.NET Empty Web Site" project
  3. Install SqlSessionStateProviderAsync 2.0 Microsoft.Data.SqlClient 5.0 nuget package
  4. Add a "DefaultConnection" connection string to the web.config file.
  5. Build the project then press “F5.”
  6. Get YSOD error below. Microsoft.Data.SqlClient.SNI.x86/x64.dlls are not copied to bin folder.

(The Microsoft.AspNet.SessionState.SqlSessionStateProviderAsync 2.0 package is not public yet, so you won't get the "error below" since the empty website doesn't try to load MS.Data.SqlClient. But you'll see MS.D.SC.dll in the bin folder, but not the SNI binaries... despite the SNI package being included in packages.config. Contact me if you want a private of the SqlSessionState package to test with - or we do plan to upload a preview to nuget shortly.)

Configuration Error
Parser Error Message: They type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception.

[DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)]
   Microsoft.Data.SqlClient.SNINativeManagedWrapperX64.SNIInitialize(Boolean useSystemDefaultSecureProtocols, IntPtr pmo) +0
   Microsoft.Data.SqlClient.SNILoadHandle..ctor() in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:19
   Microsoft.Data.SqlClient.SNILoadHandle..cctor() in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParserSafeHandles.cs:17

[TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception.]
   Microsoft.Data.SqlClient.TdsParser..cctor() in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:181

[TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception.]
   Microsoft.Data.SqlClient.TdsParser..ctor(Boolean MARS, Boolean fAsynchronous) in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\TdsParser.cs:38
   Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:1840
   Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:1727
   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 D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:539
   Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\SqlClient\SqlConnectionFactory.cs:145
   Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:148
   Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:950
   Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:2014
   Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:1419
   Microsoft.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen() in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\netfx\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:1216
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +32
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62
   Microsoft.AspNet.SessionState.<CreateSessionStateTableAsync>d__49.MoveNext() +283
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +32
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +62
   Microsoft.AspNet.SessionState.SqlSessionStateRepository.CreateSessionStateTable() +115
   Microsoft.AspNet.SessionState.SqlSessionStateProviderAsync.Initialize(String name, NameValueCollection config, SessionStateSection ssc, ConnectionStringSettings connectionString, Boolean shouldCreateTable) +1051
   Microsoft.AspNet.SessionState.SqlSessionStateProviderAsync.Initialize(String name, NameValueCollection config) +175
   System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType) +693

Expected behavior

No error. Or at least a different error becuase the site gets past this error because the SNI files are included and found in the '/bin' directory.

Further technical details

Microsoft.Data.SqlClient version: 5.0
.NET target: .Net Framework - net462 or above
SQL Server version: (2019, but I don't think that's relevant here)
Operating system: Windows

Activity

  1. lcheunglci commented on Mar 16, 2023

    @lcheunglci
    Contributor

    Thanks @StephenMolloy for bring this issue to our attention and your insight in root cause of the issue. I believe there are few other similar issues where for ASP.NET publish/deployment where the NativeSNI binaries appear to be missing, and I believe most involved a workaround with a shadow copy mechanism. #745 #727 #1318 #354 and a few others. In #612 (comment) @cheenamalhotra made a suggestion to modify the add Microsoft.Data.SqlClient.SNI.targets from our SNI repro that may resolve the issue, and we can probably make a private nuget to test out, but we'll get back to you on that.

  2. added
    Area\Native SNI
    and removed on Mar 16, 2023
  3. self-assigned this
    on Mar 21, 2023
  4. moved this from To triage to Backlog in SqlClient Boardon Jan 8, 2026
  5. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

  6. github-actions commented on Sep 17, 2026

    @github-actions

    🔍 Triage Summary (on-demand re-triage)

    Check Result
    Issue type Bug
    Environment All required environment details provided for investigation
    Area Area\Native SNI
    Duplicates Potentially related: #745, #727, #1318, #354, #612 (all involve Native SNI binaries missing in ASP.NET publish/deploy or "Website" project scenarios)
    Regression Not indicated — this is a packaging/deployment limitation, not a behavioral regression from a prior working version

    Analysis

    This issue reports that Microsoft.Data.SqlClient.SNI native binaries are not copied into the bin output of legacy ASP.NET "Web Site" projects, causing a DllNotFoundException at runtime. Because "Web Site" projects are not MSBuild-based, the .targets file that normally copies the native SNI DLLs to the output directory is never invoked, and since the SNI binaries live in the package's build folder (not lib), NuGet/VS .refresh mechanisms used for lib assemblies don't apply either. This is a packaging/deployment gap affecting Native SNI on .NET Framework, consistent with several previously reported issues in the same area. Severity: P2 — affects a legacy project type with a known (if inconvenient) workaround, not a regression or data-loss issue.

    Next Steps

    Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.

    Generated by SqlClient Issue Auto-Triage for #1955 · copilot · auto · 52.6 AIC · ⌖ 12.1 AIC · ⊞ 11.9K · ◷

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area\Native SNI

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions