You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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:
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 -->
<ItemGroupCondition="'$(Configuration)' == 'Release'">
<TrimmableAssemblyInclude="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.
Activity
github-actions commentedon Oct 21, 2026
LeDahu22 commentedon Oct 21, 2026
Here is the exception and StackTrace :
github-actions commentedon Oct 21, 2026
🔍 Triage Summary (updated after author response)
Analysis
The provided stack trace shows a
TypeInitializationExceptionforMicrosoft.Data.SqlClient.TdsParserthrown fromSqlConnectionInternal.LoginNoFailoverwhen opening the first connection in a MAUI Android app built in Release/AOT. This points to a static constructor/initializer inTdsParser(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
TdsParserstatic initialization (static fields,LocalAppContextSwitches, SNI/platform setup, reflection orType.GetTypeusage) and what changed between 7.0.2 and 7.1.0 under trimming/AOT.TypeInitializationException(the message text was not resolved in the trace). Also share thePublishTrimmed/RunAOTCompilationsettings, and whether settingSwitch.Microsoft.Data.SqlClient.EnableAppConfig=falsechanges behavior.cheenamalhotra commentedon Oct 26, 2026
I think it was fixed with #4700 and #4770 on release/7.1 branch - fix will come with 7.1.2 release.
GabrielFarfan commentedon Nov 9, 2026
A workaround for anyone on 7.1.1 until 7.1.2 ships. We hit the same failure in a
net10.0-androidRelease build (Android 16 arm64 emulator, .NET SDK 10.0.403,androidworkload 36.1.118). It traces to the eagerSNILoadHandleinitialization that #4700 fixes. The inner exceptions were: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.dlluntouched, as the SDK's defaultTrimMode=partialdoes. When the trimmer processes SqlClient, it foldsOperatingSystem.IsWindows()and drops the native SNI branch, and the first open works. Either of these worked for us on 7.1.1:or
<TrimMode>full</TrimMode>. With the item, the trimmedMicrosoft.Data.SqlClient.dllno longer containsSNILoadHandleorSNIInitialize. 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.