Repository navigation
Open
Description
When developing SqlClient using Visual Studio I want to be able to run the manual tests to make sure that I haven't broken anything. With the tests configured correctly so that they can be run correctly from the commandline it is impossible to run them from within Visual Studio.
Picking a simple test example, this is what you get:
Microsoft.Data.SqlClient.ManualTesting.Tests.AdapterTest.AutoGenBulkUpdateTest
Source: AdapterTest.cs line 1204
Duration: 72 ms
Message:
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.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
Stack Trace:
TdsParser.ctor(Boolean MARS, Boolean fAsynchronous) line 34
SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) line 1567
SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) line 1444
SqlInternalConnectionTds.ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool, Func`3 accessTokenCallback) line 525
SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) line 138
DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) line 153
DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) line 802
DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) line 1977
DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) line 1361
DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) line 1261
DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) line 306
DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) line 963
DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) line 43
SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides) line 1970
SqlConnection.Open(SqlConnectionOverrides overrides) line 1413
SqlConnection.Open() line 1390
AdapterTest.AutoGenBulkUpdateTest() line 1211
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
----- Inner Stack Trace -----
TdsParserStateObjectFactory.get_EncryptionOptions() line 22
TdsParser.cctor() line 79
----- Inner Stack Trace -----
SniNativeMethods.SNIInitialize(IntPtr pmo)
SniNativeMethods.SniInitialize(IntPtr pmo) line 58
SniNativeWrapper.SNIInitialize(IntPtr pmo) line 164
SniNativeWrapper.SNIInitialize() line 278
SNILoadHandle.ctor() line 38
SNILoadHandle.ctor() line 22
SNILoadHandle.cctor() line 20
Without the ability to trigger the CI as a contributor the local test experience becomes much more important. Currently it is not useful and does not allow test information to be gathered in a sensible way.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
- StatusShow more project fieldsBacklog

Activity
Wraith2 commentedon May 11, 2025
Any update on this? It would be very useful when fixing issues if I could run the tests in VS.
paulmedynski commentedon May 12, 2025
Sorry, got distracted trying to figure out weird MSBuild behavour related to #3311. I'll give this a shot with VS Code first (my daily driver), and the VS to see if there are any differences.
paulmedynski commentedon May 12, 2025
The
AutoGenBulkUpdateTesttest ran fine for me via VS Code using WSL. That used the .NET 9 runtime on Linux, so SNI isn't a factor.I tried the same via VS Code using Windows, and it can't build the tests. VS Code's C# Dev Kit isn't smart enough to regocnize multi-target projects and let you choose the target, so it's trying to use the .NET Framework MDS project for .NET 9 tests, which doesn't work (yet - see #3311).
Finally, I was able to run
AutoGenBulkUpdateTestvia VS 2022 for .NET 9 first try. I just opened the MDS solution, found the test in the Test Explorer, and hit the Run button:This was against a working directory that already had everything built (via command-line msbuild) from my previous attempts, so maybe that makes a difference. Can you try running via VS after building everything via msbuild?
Wraith2 commentedon May 12, 2025
Yes, oddly that now works though it hasn't in the past.
Wraith2 commentedon May 12, 2025
Try this.
with vs closed.
build in cli should succeed.
then open the project in vs.
build in vs should succeed.
now with vs still open run those same cli commands again.
build in cli should succeed
build in vs should now fail.
So it can be made to work if you do the right things in the right order. My experience is usually that I do a bunch of work, add a test to cover it and then find that it can't be executed in debug mode for netcore in vs. I could probably keep re-running various build combinations until I find the right one that lets me run it but it's frustrating and time consuming to keep doing that even on fast hardware.
paulmedynski commentedon May 12, 2025
Yep, your experience is similar to mine, and I'm a CLI-only guy. The current build setup isn't terribly repeatable or deterministic. Ben's work to merge the .NET Framework and .NET projects will help by removing one dimension, and then I have plans to see how we can further un-spaghetti things to simplify what/when/how we build. I'll keep this issue open to make sure this particular quirk is addressed during that other re-work.
priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
🔍 Triage Summary (on-demand re-triage)
Area\Native SNIAnalysis
This is a build/tooling reliability issue: when running .NET 9 manual tests inside Visual Studio,
Microsoft.Data.SqlClient.SNI.dllis not reliably present/copied alongside the test binaries depending on the prior sequence of CLImsbuildinvocations vs. opening the solution in VS, causingDllNotFoundExceptionduringSNILoadHandle/TdsParserstatic initialization. Comments confirm the failure is order-dependent (build via CLI first, then VS, then CLI again reproduces it) and is understood to stem from the split netfx/netcore project structure and non-deterministic build outputs; a maintainer noted the ongoing unification of the .NET Framework and .NET projects (seearchitecture.instructions.md's "Unified Project Model") is expected to help resolve this class of issue. Severity: P2 — developer productivity / inner-loop issue, not a runtime/production bug, but it blocks contributors from running manual tests inside Visual Studio.Next Steps
BuildTestsNetCore/BuildTestsNetFxmsbuild targets and output/copy-local behavior forMicrosoft.Data.SqlClient.SNI.dll(and its runtime counterpart) to ensure test output directories are deterministically populated regardless of build invocation order (CLI vs. VS), now that the project has moved toward the unifiedsrc/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csprojmodel described in.github/instructions/architecture.instructions.md.