Skip to content

TDSParser Error #2022

Open
Open

Description

@MattH678

Hi,

As lots of people have previously mentioned this bug, I will try and keep this short and concise.
I am getting the bug within a VSTO Excel plugin whereby an exception is thrown when attempting to open a SQL connection. It appears that the appropriate SNI libraries are not being copied properly in the publish folder, but are in the debug and release folders.
Authentication with Azure works fine for KeyVault, It is just AZ Sql that it fails with.

I have tried the solution listed in #446, https://learn.microsoft.com/en-us/sql/connect/ado-net/sqlclient-troubleshooting-guide?view=sql-server-ver15#unable-to-load-native-sni-server-name-indication-library. My attempts to fix the problem range from shadow copying the library, attempting to have a reference within the project to SNI, migrating from package.config to packagereference, forcing a local copy...the list goes on.

I will freely admit I am not an expert at MSBuild and could really do with some help, If I have missed something please let me know, I'm very very lost...

Code:
public DataSet RunReaderCommand(string command)
{
                DataSet ds;
                SqlConnectionStringBuilder = new SqlConnectionStringBuilder();
                SqlConnectionStringBuilder.DataSource = Az_SQLDB_svrName;
                SqlConnectionStringBuilder.InitialCatalog = Initial_DatabaseName;
                SqlConnectionStringBuilder.TrustServerCertificate = true;
                SqlConnectionStringBuilder.PersistSecurityInfo = false;
                SqlConnectionStringBuilder.Authentication = SqlAuthenticationMethod.ActiveDirectoryDefault;
                SqlConnection = new SqlConnection(SqlConnectionStringBuilder.ConnectionString);
                SqlConnection.Open();
                SqlCommand SqlCommand = new SqlCommand(command, SqlConnection);
                SqlCommand.CommandType = CommandType.Text;

                sqlDataAdapter.SelectCommand = SqlCommand;

                ds = new DataSet(Table.ToString());
                sqlDataAdapter.Fill(ds);
                SqlConnection.Close();
                return ds;
}
Exception message:
The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.:
Stack trace:

   at System.Data.SqlClient.TdsParser..ctor(Boolean MARS, Boolean fAsynchronous)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()

Further technical details

Microsoft.Data.SqlClient version: 5.2.0-preview1.23109.1 <--- I switched to the preview to check I couldn't force it to copy (It didn't)
Microsoft.Data.SqlClient.SNI version: 5.1.0
.NET Framework 4.8
SQL Server version: AZ Sql
Operating system: Azure VM Windows Pro 10/11

Additional context
This is my build output:

ResolveAssemblyReferences:
1>  Primary reference "Microsoft.Data.SqlClient.SNI".
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Data.SqlClient.SNI". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>          For SearchPath "{CandidateAssemblyFiles}".
1>          Considered "C:\Users\Mharr\.nuget\packages\microsoft.sqlserver.types\160.1000.6\build\net462\..\..\runtimes\win-x86\native\SqlServerSpatial160.dll",
1>  			but its name "SqlServerSpatial160"
1>  			didn't match the expected name "Microsoft.Data.SqlClient.SNI".
1>          Considered "C:\Users\Mharr\.nuget\packages\microsoft.sqlserver.types\160.1000.6\build\net462\..\..\runtimes\win-x64\native\SqlServerSpatial160.dll",
1>  			but its name "SqlServerSpatial160"
1>  			didn't match the expected name "Microsoft.Data.SqlClient.SNI".
1>          Considered "C:\Users\Mharr\.nuget\packages\microsoft.web.webview2\1.0.1722.45\build\\..\runtimes\win-x86\native\WebView2Loader.dll",
1>  			but its name "WebView2Loader"
1>  			didn't match the expected name "Microsoft.Data.SqlClient.SNI".
1>          Considered "C:\Users\Mharr\.nuget\packages\microsoft.web.webview2\1.0.1722.45\build\\..\runtimes\win-x64\native\WebView2Loader.dll",
1>  			but its name "WebView2Loader"
1>  			didn't match the expected name "Microsoft.Data.SqlClient.SNI".
1>          Considered "C:\Users\Mharr\.nuget\packages\microsoft.web.webview2\1.0.1722.45\build\\..\runtimes\win-arm64\native\WebView2Loader.dll",
1>  			but its name "WebView2Loader"
1>  			didn't match the expected name "Microsoft.Data.SqlClient.SNI".
1>          For SearchPath "{TargetFrameworkDirectory}".
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Microsoft.Data.SqlClient.SNI.winmd", but it didn't exist.
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Microsoft.Data.SqlClient.SNI.dll", but it didn't exist.
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Microsoft.Data.SqlClient.SNI.exe", but it didn't exist.
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades\Microsoft.Data.SqlClient.SNI.winmd", but it didn't exist.
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades\Microsoft.Data.SqlClient.SNI.dll", but it didn't exist.
1>          Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades\Microsoft.Data.SqlClient.SNI.exe", but it didn't exist.
1>          For SearchPath "{AssemblyFoldersFromConfig:C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\AssemblyFolders.config,v4.8}".
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\SqlDb\Microsoft.Data.SqlClient.SNI.winmd", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\SqlDb\Microsoft.Data.SqlClient.SNI.dll", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\SqlDb\Microsoft.Data.SqlClient.SNI.exe", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\PublicAssemblies\Microsoft.Data.SqlClient.SNI.winmd", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\PublicAssemblies\Microsoft.Data.SqlClient.SNI.dll", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\PublicAssemblies\Microsoft.Data.SqlClient.SNI.exe", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\v4.5\Microsoft.Data.SqlClient.SNI.winmd", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\v4.5\Microsoft.Data.SqlClient.SNI.dll", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\v4.5\Microsoft.Data.SqlClient.SNI.exe", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Data.SqlClient.SNI.winmd", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Data.SqlClient.SNI.dll", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.Data.SqlClient.SNI.exe", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.Data.SqlClient.SNI.winmd", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.Data.SqlClient.SNI.dll", but it didn't exist.
1>          Considered "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.Data.SqlClient.SNI.exe", but it didn't exist.
1>          For SearchPath "{Registry:Software\Microsoft\.NETFramework,v4.8,AssemblyFoldersEx}".
1>          Considered AssemblyFoldersEx locations.
1>          For SearchPath "{AssemblyFolders}".
1>          Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\Microsoft.Data.SqlClient.SNI.winmd", but it didn't exist.
1>          Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\Microsoft.Data.SqlClient.SNI.dll", but it didn't exist.
1>          Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\Microsoft.Data.SqlClient.SNI.exe", but it didn't exist.
1>          For SearchPath "{GAC}".
1>          Considered "Microsoft.Data.SqlClient.SNI", which was not found in the GAC.
1>          For SearchPath "{RawFileName}".
1>          Considered treating "Microsoft.Data.SqlClient.SNI" as a file name, but it didn't exist.
1>          For SearchPath "bin\Release\".
1>          Considered "bin\Release\Microsoft.Data.SqlClient.SNI.winmd", but it didn't exist.
1>          Considered "bin\Release\Microsoft.Data.SqlClient.SNI.dll", but it didn't exist.
1>          Considered "bin\Release\Microsoft.Data.SqlClient.SNI.exe", but it didn't exist.

Activity

  1. added
    Area\Native SNI
    and removed on Apr 26, 2023
  2. JRahnama commented on May 2, 2023

    @JRahnama
    Contributor

    @MattH678 thanks for opening the issue. We will investigate this.

  3. moved this from To triage to Backlog in SqlClient Boardon Jan 10, 2026
  4. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

  5. 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: #446, #612, #1146, #2173, #3081 (this issue is already linked as a child of tracking issue #4129 "SNI loading issues")
    Regression Not indicated (reporter did not report a previously-working version; issue reproduces on both the released 5.1.x and preview 5.2.0 builds)

    Analysis

    This is a .NET Framework 4.8 build/publish issue where Microsoft.Data.SqlClient.SNI.dll is not copied to the publish output of a VSTO Excel add-in, causing TdsParser's static constructor to fail and surface as The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception. The MSBuild log shows ResolveAssemblyReferences cannot locate Microsoft.Data.SqlClient.SNI at all (not just at publish time), suggesting the reference/native-asset resolution for VSTO/ClickOnce-style publish pipelines is not picking up the SNI native package correctly — consistent with several other native-SNI deployment issues already tracked against this repo (e.g. #446, #2173, #3081). Severity: P2 (blocks connectivity entirely for affected VSTO/publish scenarios, but has known workarounds for other project types and is already tracked under a parent SNI-loading epic).

    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 #2022 · copilot · auto · 43.6 AIC · ⌖ 14.6 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