In my .net maui 10 ios app, why do I get error "TypeInitialization_Type, Microsoft.Data.SqlClient.Tds-Parser" in Release mode during SELECT?

Kurt K 236 Reputation points
2026-11-09T18:57:06.2266667+00:00

I have a production .net maui 9 ios (only) app, on the Apple AppStore, that has been working well for about the last year using Microsoft.Data.SqlClient v6.0.2.

This production app targets either Azure SQL Database, or a SQL Server database on a private local network. In either case the app connects to the database using the client's private WiFi. When connecting to Azure SQL Database, an encrypted connection is specified in the connection string.

I have been upgrading the app to .net maui 10.

The error started happening after recently upgrading Microsoft.Data.SqlClient to the latest version, v7.1.1, but only in Release mode. Debug mode works fine.

The small amount of research I have already done indicates the problem may be due to trimming done for the AOT compilation. What is the best way to proceed?

Developer technologies | .NET | .NET Multi-platform App UI

Answer accepted by question author
Nguyen Dam (WICLOUD CORPORATION) 1,335 Reputation points Microsoft External Staff Moderator
2026-11-10T03:50:58.73+00:00

Hello @Kurt K and thank you for reaching out. 

As you have found, this appears to match the Microsoft.Data.SqlClient 7.1.0/7.1.1 AOT regression tracked in GitHub issue #4889. 

I was also able to reproduce the same TdsParser initialization error with Microsoft.Data.SqlClient 7.1.1 using .NET 10 MAUI on an Android x64 emulator, in Release mode with RunAOTCompilation=true. This suggests that the issue is not specific to iOS, although the exact cause of the iOS failure has not been independently confirmed.

According to the SqlClient maintainer, the regression was likely addressed by fixes in PRs #4700 and #4770, which are expected to be included in version 7.1.2. 

Since you are already planning to try 7.1.2, I would recommend testing it with your iOS Release build once available. In the meantime, using an earlier supported SqlClient version that works in Release mode would be a reasonable workaround. 

If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation. Thank you. 

Was this answer helpful?

1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. AI answer

    2026-11-09T18:58:10.1566667+00:00

    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^.

    1. 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^.

    1. Delete the project’s bin and obj directories so no 7.1.1 assets remain.
    2. Restore and publish an actual device build:
    dotnet restore
    dotnet publish -f net10.0-ios -c Release -r ios-arm64
    
    1. 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

    1. [7.1.1 Regression] AOT compilation issue - GitHub
    2. SqlClient driver support lifecycle
    3. Install, update, and deploy Microsoft.Data.SqlClient
    4. Trim a .NET MAUI app
    5. What's new in .NET MAUI for .NET 10
    6. Native AOT deployment on iOS and Mac Catalyst
    7. Linking a .NET MAUI iOS app
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.