runtime: [regression/8.0.0] [iOS] After migration from net7.0-ios to net8.0-ios app crashes randomly in release mode with UseInterpreter="False"

Description

Sorry for the long explanation.

Due to my experience with migrations in the past, it was not planned to migrate to Maui NET8 soon. But after upgrading my Mac to Sonoma, i was forced, also to upgrade XCODE and i thought, it would be time, to update to the latest Maui Version as well.

I am working for a very long time (end of 2021) on a quite big and complex app and a solid foundation for more apps with MAUI in the future (?). My experience with Maui / Xamarin is much longer.

At the end of each development day, the iOS version is always tested on a real device in release mode. I set a high value on not being forced, to use the Interpreter in release mode and with an app in the store.

My release configuration:

	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'">
		<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
		<MtouchLink>SdkOnly</MtouchLink>
		<UseInterpreter>False</UseInterpreter>
		<ArchiveOnBuild>true</ArchiveOnBuild>
		<CreatePackage>false</CreatePackage>
		<CodesignEntitlement>Entitlements.plist</CodesignEntitlement>
		<ProvisioningType>manual</ProvisioningType>
		<CodesignProvision>The Profile</CodesignProvision>
		<CodesignKey>The Key</CodesignKey>
	</PropertyGroup>

My build command:

sudo dotnet publish TheApp.csproj -v d -c Release -f net8.0-ios /t:Run /p:RuntimeIdentifier=ios-arm64 /p:MtouchLink=SdkOnly /p:ArchiveOnBuild=True /p:00008101-001C49DC1E10001E

Although i try to keep my external dependencies at a very minimum, it does not work without some:

	<ItemGroup>
		<PackageReference Include="SkiaSharp" Version="2.88.6" />
		<PackageReference Include="SkiaSharp.HarfBuzz" Version="2.88.6" />
		<PackageReference Include="sqlite-net-pcl" Version="1.9.141-beta" />
		<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.6" />
		<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
		<PackageReference Include="MediatR" Version="12.0.1" />
		<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.1.0" />
		<PackageReference Include="LiveChartsCore.SkiaSharpView.Maui" Version="2.0.0-beta.800" />
		<PackageReference Include="Camera.MAUI" Version="1.4.4" />
		<PackageReference Include="Google.Apis.Drive.v3" Version="1.62.0.3155" />
	</ItemGroup>

net7.0-ios

  • Good: Debug mode - no crashes at runtime
  • Good: Release mode with interpreter enabled - no crashes at runtime
  • Good: Release mode with interpreter disabled - no crashes at runtime.

net8.0-ios (with the same code base)

  • Good: Debug mode - no crashes at runtime
  • Good: Release mode with interpreter enabled - no crashes at runtime
  • BAD: Release mode with interpreter disabled - random crashes at runtime

It is now the fourth day, where i am trying to find the reason for that behaviour.

My results so far:

  • Most of the time, it crashes without a stacktrace.
  • When a stacktrace is produced, the top native entry is always the same
	0x1079fdc10 - /private/var/containers/Bundle/Application/C04EAD60-C238-4588-A960-962F847CC77A/PublicStaging.app/TheApp : AppleCryptoNative_X509ImportCertificate
	. . .

The top managed entry always shows the “InitializeComponent” method of a page

	  at TheApp.Module.AAA.ListPage:InitializeComponent <0x01338>
	  . . .

Because of the complex and deep hierarchy of custom UI-components, the app first crashed right at the start. I tried to narrow down the problem, by disabling some parts of the UI.

One of many, many, many, … experiments:

After some investigation, i randomly disabled a part in the UI, where i use a HorizontalStackLayout with BindableLayout.ItemsSource and suddenly, i could at least start the app. Of course, it crashed then in another part of the app.

Later i tried to replace this specific part of the UI with a CollectionView, and got some interesting results.

Setting the height of the CollectionView with the following code, does not crash:

        HeightRequest="{StaticResource daterange_selector_height}"
        ...
        <OnIdiom
                x:Key="daterange_selector_height"
                x:TypeArguments="x:Double"
                Default="40"
                Phone="34"
                Tablet="34"/>

Setting the height of the CollectionView with this code, crashes immediately:

        HeightRequest="34"

My questions are:

  • What did change between net7.0-ios and net8.0-ios, that could explain this specific problem?
  • Is there anything, i can do or any data i could provide?
  • The process of debugging this class of errors is extremely frustrating and time consuming. Is there more information about tools or best practices?

Many thanks in advance!

Steps to Reproduce

Sorry, i tried to create a sample app to isolate the problem. But unfortunately it is not possible.

Link to public reproduction project repository

No response

Version with bug

8.0.0-rc.2.9373

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.96

Affected platforms

iOS

Affected platform versions

iOS 16.2

Did you find any workaround?

I tried, but no.

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

Great news

Tested with the full app.

Maui version

maui  8.0.0-rc.2.9511/8.0.100-rc.2  SDK 8.0.100-rc.2  

in release mode, with the following settings,

 <MtouchLink>SdkOnly</MtouchLink>
 <MtouchUseLlvm>true</MtouchUseLlvm>
 <UseInterpreter>false</UseInterpreter>

runs fast and without any crash.

Thank you very much for your work and time!

MAUI shipped an intermediate release yesterday: https://www.nuget.org/packages/Microsoft.NET.Sdk.Maui.Manifest-8.0.100-rc.2/8.0.0-rc.2.9511 with which I am not able to reproduce the crashes from any of the two scenarios you described in the Test.md file.

Could you please try to update your MAUI workload to this newest version 8.0.0-rc.2.9511 and see if it helps?

This can be done by doing:

dotnet workload update
...
dotnet workload restore
...

To verify the version you can then:

dotnet workload list
Installed Workload Id      Manifest Version                  Installation Source
--------------------------------------------------------------------------------
maui                       8.0.0-rc.2.9511/8.0.100-rc.2      SDK 8.0.100-rc.2

Please let me know, if this helps/unblocks you, and I will continue investigating the root cause of the issues you were experiencing with the older version.

.NET SDK:
 Version:   8.0.100-rc.2.23502.2
 Commit:    0abacfc2b6

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  14.0
 OS Platform: Darwin
 RID:         osx-arm64
 Base Path:   /usr/local/share/dotnet/sdk/8.0.100-rc.2.23502.2/

.NET workloads installed:
 [maui]
   Installation Source: SDK 8.0.100-rc.2
   Manifest Version:    8.0.0-rc.2.9373/8.0.100-rc.2
   Manifest Path:       /usr/local/share/dotnet/sdk-manifests/8.0.100-rc.2/microsoft.net.sdk.maui/8.0.0-rc.2.9373/WorkloadManifest.json
   Install Type:        FileBased


Host:
  Version:      8.0.0-rc.2.23479.6
  Architecture: arm64
  Commit:       0b25e38ad3

.NET SDKs installed:
  6.0.202 [/usr/local/share/dotnet/sdk]
  6.0.203 [/usr/local/share/dotnet/sdk]
  6.0.300 [/usr/local/share/dotnet/sdk]
  6.0.301 [/usr/local/share/dotnet/sdk]
  6.0.400 [/usr/local/share/dotnet/sdk]
  6.0.402 [/usr/local/share/dotnet/sdk]
  6.0.403 [/usr/local/share/dotnet/sdk]
  6.0.404 [/usr/local/share/dotnet/sdk]
  6.0.405 [/usr/local/share/dotnet/sdk]
  6.0.408 [/usr/local/share/dotnet/sdk]
  6.0.410 [/usr/local/share/dotnet/sdk]
  7.0.100 [/usr/local/share/dotnet/sdk]
  7.0.101 [/usr/local/share/dotnet/sdk]
  7.0.200-preview.22628.1 [/usr/local/share/dotnet/sdk]
  7.0.203 [/usr/local/share/dotnet/sdk]
  7.0.304 [/usr/local/share/dotnet/sdk]
  8.0.100-rc.2.23502.2 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.16 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.18 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  x64   [/usr/local/share/dotnet/x64]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

I can reproduce the crash, and it goes away if I disable LLVM:

<PropertyGroup>
    <MtouchUseLlvm>false</MtouchUseLlvm>
</PropertyGroup>

The reason it only fails in the Release configuration is because we only enable LLVM by default in the Release configuration.

I’m going to move this to the dotnet/runtime repository, since this is a runtime/llvm issue.

I tested with .NET 8.0.100-rc.2.23502.2.

@SailDev Note that somebody other than me will take over from now, so you’ll have to send the project to them as well.

Can you try adding this to your csproj, that should provide better symbols for the native frames:

<PropertyGroup>
    <NoSymbolStrip>true</NoSymbolStrip>
</PropertyGroup>

@rolfbjarne Can you please take a look? Thanks!