Skip to content

[7.1.1 Regression] AOT compilation issue #4889

Closed

Description

@LeDahu22

Describe the bug

After upgrading from 7.0.2 to both 7.1.0 and 7.1.1, my MAUI application is crashing on startup when compiled in AOT mode.

To reproduce

Use the following (which uses 7.0.2), compile in Release mode and click on the counter button (everything's okay, even if it's a stupid dummy code) :
Basic repro project

Upgrade to 7.1.1 and try the same, the app crashes.

Expected behavior

Application shouldn't crash compiled in AOT mode.

Further technical details

Microsoft.Data.SqlClient version: 7.1.1
.NET target: .NET 10
Target : Android 14
SQL Server version: SQL Server 2022
Operating system: Windows 11

Thank you.

Activity

  1. added theissue type on Oct 21, 2026
  2. github-actions commented on Oct 21, 2026

    @github-actions
  3. LeDahu22 commented on Oct 21, 2026

    @LeDahu22
    Author

    Here is the exception and StackTrace :

    TypeInitialization_Type, Microsoft.Data.SqlClient.TdsParser
       at Microsoft.Data.SqlClient.Connection.SqlConnectionInternal.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionOptions connectionOptions, SqlCredential credential, TimeoutTimer timeout)
       at Microsoft.Data.SqlClient.Connection.SqlConnectionInternal.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionOptions connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
       at Microsoft.Data.SqlClient.Connection.SqlConnectionInternal..ctor(DbConnectionPoolIdentity identity, SqlConnectionOptions connectionOptions, TimeoutTimer timeout, SqlCredential credential, DbConnectionPoolGroupProviderInfo providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, IDbConnectionPool pool, Func`3 accessTokenCallback, SspiContextProvider sspiContextProvider, ISqlClientMetrics metrics, RegisteredApplication registeredApplication)
       at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(SqlConnectionOptions options, ConnectionPoolKey poolKey, DbConnectionPoolGroupProviderInfo poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, TimeoutTimer timeout)
       at Microsoft.Data.SqlClient.SqlConnectionFactory.CreatePooledConnection(DbConnection owningConnection, IDbConnectionPool pool, TimeoutTimer timeout)
       at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionInternal oldConnection, TimeoutTimer timeout)
       at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.UserCreateRequest(DbConnection owningObject, TimeoutTimer timeout, DbConnectionInternal oldConnection)
       at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, TimeoutTimer timeout, DbConnectionInternal& connection)
       at Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool.WaitForPendingOpen()
    --- End of stack trace from previous location ---
       at MauiSqlClientCrash.MainPage.OnCounterClicked(Object sender, EventArgs e)
    
  4. github-actions commented on Oct 21, 2026

    @github-actions

    🔍 Triage Summary (updated after author response)

    Check Result
    Issue type Bug
    Environment All required environment details provided for investigation
    Area Area\Netcore
    Duplicates Potentially related: #1941, #2338
    Regression Likely regression from v7.0.2 (works in 7.0.2, fails in 7.1.0 and 7.1.1)

    Analysis

    The provided stack trace shows a TypeInitializationException for Microsoft.Data.SqlClient.TdsParser thrown from SqlConnectionInternal.LoginNoFailover when opening the first connection in a MAUI Android app built in Release/AOT. This points to a static constructor/initializer in TdsParser (or something it touches) using reflection, config reading, or a type that is trimmed or unsupported under AOT. The inner exception is not shown. Severity: P1/P2, since it blocks upgrades for AOT/trimmed apps.

    Next Steps

    • Assign this issue to the Copilot coding agent to investigate TdsParser static initialization (static fields, LocalAppContextSwitches, SNI/platform setup, reflection or Type.GetType usage) and what changed between 7.0.2 and 7.1.0 under trimming/AOT.
    • Optionally, @LeDahu22, please share the inner exception of the TypeInitializationException (the message text was not resolved in the trace). Also share the PublishTrimmed/RunAOTCompilation settings, and whether setting Switch.Microsoft.Data.SqlClient.EnableAppConfig=false changes behavior.
    • Review the linked issues for similar AOT/trimming problems.
    • Bisection between 7.0.2 and 7.1.0 is recommended.

    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 #4889 · copilot · auto · 23.5 AIC · ⌖ 11.5 AIC · ⊞ 13.6K · ◷

  5. added
    Repro Available ✔️Issues that are reproducible with repro provided.
    Regression 💥Issues that are regressions introduced from earlier PRs.
    on Oct 21, 2026
  6. added this to the 8.0.0-preview1 milestone on Oct 26, 2026
  7. moved this from To triage to Investigating in SqlClient Boardon Oct 26, 2026
  8. cheenamalhotra commented on Oct 26, 2026

    @cheenamalhotra
    Member

    I think it was fixed with #4700 and #4770 on release/7.1 branch - fix will come with 7.1.2 release.

  9. moved this from Investigating to Done in SqlClient Boardon Oct 26, 2026
  10. GabrielFarfan commented on Nov 9, 2026

    @GabrielFarfan

    A workaround for anyone on 7.1.1 until 7.1.2 ships. We hit the same failure in a net10.0-android Release build (Android 16 arm64 emulator, .NET SDK 10.0.403, android workload 36.1.118). It traces to the eager SNILoadHandle initialization that #4700 fixes. The inner exceptions were:

    TypeInitializationException: Microsoft.Data.SqlClient.TdsParser
     -> TypeInitializationException: Microsoft.Data.SqlClient.SNILoadHandle
     -> DllNotFoundException: Microsoft.Data.SqlClient.SNI.dll
    

    Logcat showed Shared library 'Microsoft.Data.SqlClient.SNI.dll' not loaded, p/invoke 'SNIInitialize' may fail. Debug builds didn't show it for us; they run on the Mono interpreter (UseInterpreter=true) rather than the JIT.

    It fails only when the trimmer leaves Microsoft.Data.SqlClient.dll untouched, as the SDK's default TrimMode=partial does. When the trimmer processes SqlClient, it folds OperatingSystem.IsWindows() and drops the native SNI branch, and the first open works. Either of these worked for us on 7.1.1:

    <!-- Release only: trim SqlClient while every other assembly keeps partial trimming -->
    <ItemGroup Condition="'$(Configuration)' == 'Release'">
      <TrimmableAssembly Include="Microsoft.Data.SqlClient" />
    </ItemGroup>

    or <TrimMode>full</TrimMode>. With the item, the trimmed Microsoft.Data.SqlClient.dll no longer contains SNILoadHandle or SNIInitialize. Parameters, multiple result sets, decimals, timeouts, cancellation and reconnect all passed against SQL Server 2019. Once 7.1.2 ships with #4770, the item should no longer be needed.

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

Metadata

Metadata

Assignees

Labels

Regression 💥Issues that are regressions introduced from earlier PRs.Repro Available ✔️Issues that are reproducible with repro provided.

Type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions