Pin Microsoft.Data.SqlClient to 7.0.3 (or 6.1.7 LTS) because the matching upstream issue identifies a 7.1.0/7.1.1 MAUI AOT regression involving TdsParser initialization.
The reported regression occurs after upgrading from 7.0.2 to 7.1.x and matches the release/AOT-only TdsParser failure described here ^1^.
Recommended production path
- Pin the package explicitly in the MAUI project:
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient"
Version="7.0.3" />
</ItemGroup>
Alternatively, use the current LTS line:
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient"
Version="6.1.7" />
</ItemGroup>
7.0.3 is the latest patch in the 7.0 STS line. 6.1.7 is LTS through August 14, 2028 and is preferable when 7.x functionality is unnecessary ^2^.
- Delete the project’s
bin and obj directories so no 7.1.1 assets remain.
- Restore and publish an actual device build:
dotnet restore
dotnet publish -f net10.0-ios -c Release -r ios-arm64
- Install that published build on a physical device and test both database paths. This matters because simulator and Debug behavior do not reproduce all device trimming/AOT behavior.
Do not return to 6.0.2 for production merely because it worked previously; select a currently supported patch line instead. Microsoft currently lists 7.1.1, 7.0.3, and 6.1.7 as supported releases ^3^.
Confirm trimming involvement
The Release/Debug difference is consistent with trimming, but the exception alone does not prove that trimming is the cause. In .NET MAUI iOS, device builds use trimming, while simulator behavior can differ. Full trimming removes code that is not statically reachable ^4^.
Temporarily enable detailed warnings:
<PropertyGroup>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
</PropertyGroup>
Publish again and inspect warnings mentioning:
-
Microsoft.Data.SqlClient
-
TdsParser
- reflection or dynamically accessed members
- SNI or platform initialization
.NET 10 enables trimmer warnings by default in more Apple configurations ^5^.
If <PublishAot>true</PublishAot> is present, this is specifically Native AOT, which automatically performs full trimming. Microsoft states that a single trim/AOT warning means the application may not be Native-AOT-compatible, including when the warning originates in a third-party library ^6^. Do not set TrimMode when Native AOT is enabled.
Diagnostic preservation test
If the failure remains on 7.0.3 or 6.1.7, temporarily root the assembly:
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier(
'$(TargetFramework)')) == 'ios'">
<TrimmerRootAssembly Include="Microsoft.Data.SqlClient" />
</ItemGroup>
TrimmerRootAssembly prevents the specified assembly and its statically understood dependencies from being removed ^7^.
If this eliminates the crash, capture:
- the complete exception, including every
InnerException;
- all IL2xxx and IL3xxx warnings;
- the selected package version;
- whether
PublishAot is enabled;
- device architecture and iOS version.
Assembly-wide preservation is a diagnostic workaround, not proof that every dynamically loaded native dependency is available. If 7.0.3 works without preservation while 7.1.1 fails from the same published project, add that reproduction to the existing SqlClient regression rather than suppressing warnings or broadly preserving assemblies.
References
- [7.1.1 Regression] AOT compilation issue - GitHub
- SqlClient driver support lifecycle
- Install, update, and deploy Microsoft.Data.SqlClient
- Trim a .NET MAUI app
- What's new in .NET MAUI for .NET 10
- Native AOT deployment on iOS and Mac Catalyst
- Linking a .NET MAUI iOS app