Skip to content

Net9 Tests do not run in Visual Studio #3193

Open

Description

@Wraith2

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:

Image

 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.

Activity

  1. Wraith2 commented on May 11, 2025

    @Wraith2
    ContributorAuthor

    Any update on this? It would be very useful when fixing issues if I could run the tests in VS.

  2. paulmedynski commented on May 12, 2025

    @paulmedynski
    Contributor

    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.

  3. paulmedynski commented on May 12, 2025

    @paulmedynski
    Contributor

    The AutoGenBulkUpdateTest test 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 AutoGenBulkUpdateTest via 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:

    Image

    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?

    msbuild -t:Clean
    msbuild
    msbuild -t:BuildTestsNetFx -p:TF=net462
    msbuild -t:BuildTestsNetCore -p:TF=net9.0
    
  4. Wraith2 commented on May 12, 2025

    @Wraith2
    ContributorAuthor

    Yes, oddly that now works though it hasn't in the past.

  5. Wraith2 commented on May 12, 2025

    @Wraith2
    ContributorAuthor

    Try this.
    with vs closed.

    msbuild /t:clean
    msbuild /p:Configuration=Release
    msbuild /t:BuildTestsNetCore /p:TargetNetCoreVersion=net9.0 /p:Configuration=Release
    

    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.

  6. paulmedynski commented on May 12, 2025

    @paulmedynski
    Contributor

    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.

  7. removed their assignment
    on Oct 23, 2025
  8. moved this from To triage to Backlog in SqlClient Boardon Nov 6, 2025
  9. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

  10. 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 (SqlClient repo tip / net9.0 TFM, Windows + Visual Studio 2022, detailed msbuild repro steps and stack trace)
    Area Area\Native SNI
    Duplicates Potentially related: #4129 (parent tracking issue "SNI loading issues")
    Regression Not indicated — long-standing build/tooling inconsistency rather than a version regression

    Analysis

    This is a build/tooling reliability issue: when running .NET 9 manual tests inside Visual Studio, Microsoft.Data.SqlClient.SNI.dll is not reliably present/copied alongside the test binaries depending on the prior sequence of CLI msbuild invocations vs. opening the solution in VS, causing DllNotFoundException during SNILoadHandle/TdsParser static 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 (see architecture.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

    • Recommend assigning to Copilot coding agent to investigate the BuildTestsNetCore/BuildTestsNetFx msbuild targets and output/copy-local behavior for Microsoft.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 unified src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj model described in .github/instructions/architecture.instructions.md.
    • Review linked parent issue SNI loading issues #4129 ("SNI loading issues") for overlapping root-cause work before starting a new fix, to avoid duplicate effort.
    • Since this is tied to the netfx/netcore unification effort already underway, consider verifying whether the unified project changes have already resolved or improved this scenario before scheduling further investigation.

    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 #3193 · copilot · auto · 33.2 AIC · ⌖ 13.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

    No labels
    No labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions