dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.06k stars 1.73k forks source link

XCode 16/iOS 18 - Stable app now crashes almost immediately. #25229

Open RobTF opened 3 days ago

RobTF commented 3 days ago

Description

Our app was reasonably stable - enough for production, however our iOS build machine died and the new one runs MacOS 15 with XCode 16.

We have updated to the latest iOS workload and managed to make one app work stably by using a nightly MAUI build (8.0.99-ci.net8.24477.4) however the other app is very unstable and crashes out in the gut of XAML parsing code.

Any ideas? Are we waiting on the MAUI team to release something more stable for iOS 18/Xcode 16???

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.91 SR9.1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.91 SR9.1

Affected platforms

iOS

Affected platform versions

iOS 18, XCode 16

Did you find any workaround?

No

Relevant log output

error MT1046: Additional output: 2024-10-12 17:48:06.721 MyApp[1080:118663] Unhandled managed exception: Exception has been thrown by the target of an invocation. (System.Reflection.TargetInvocationException)
error MT1046: Additional output:    at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
error MT1046: Additional output:    at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
error MT1046: Additional output:    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
error MT1046: Additional output:    at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
error MT1046: Additional output:    at System.Activator.CreateInstance(Type type, Boolean nonPublic)
error MT1046: Additional output:    at System.Activator.CreateInstance(Type type)
error MT1046: Additional output:    at Microsoft.Maui.Controls.ElementTemplate.<>c__DisplayClass5_0.<.ctor>b__0()
error MT1046: Additional output:    at Microsoft.Maui.Controls.ElementTemplate.CreateContent()
error MT1046: Additional output:    at Microsoft.Maui.Controls.Handlers.Items.TemplatedCell.Bind(DataTemplate template, Object bindingContext, ItemsView itemsView)
error MT1046: Additional output:
error MT1046: Additional output: =================================================================
error MT1046: Additional output:    Native Crash Reporting
error MT1046: Additional output: =================================================================
error MT1046: Additional output: Got a SIGABRT while executing native code. This usually indicates
error MT1046: Additional output: a fatal error in the mono runtime or one of the native libraries
error MT1046: Additional output: used by your application.
error MT1046: Additional output: =================================================================
error MT1046: Additional output:
error MT1046: Additional output: =================================================================
error MT1046: Additional output:    Native stacktrace:
error MT1046: Additional output: =================================================================
error MT1046: Additional output:    0x103994374 - /private/var/containers/Bundle/Application/C368ABBA-D417-45D3-9FD6-9512CDC8E349/MyApp.app/MyApp : AppleCryptoNative_X509ImportCollection
error MT1046: Additional output:    0x10397bd9c - /private/var/containers/Bundle/Application/C368ABBA-D417-45D3-9FD6-9512CDC8E349/MyApp.app/MyApp : AppleCryptoNative_X509ImportCollection
error MT1046: Additional output:    at Microsoft.Maui.Controls.Handlers.Items.ItemsViewController`1[[Microsoft.Maui.Controls.CarouselView, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].UpdateTemplatedCell(TemplatedCell cell, NSIndexPath indexPath)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Handlers.Items.CarouselViewController.GetCell(UICollectionView collectionView, NSIndexPath indexPath)
error MT1046: Additional output: --- End of stack trace from previous location ---
error MT1046: Additional output:    at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 2719
error MT1046: Additional output:    at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 64
error MT1046: Additional output:    at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 96
error MT1046: Additional output:    at MyApp.Program.Main(String[] args) in /Users/rob/source/MyApp/myapp/MyApp/Platforms/iOS/Program.cs:line 22
error MT1046: Additional output: Exception has been thrown by the target of an invocation. (System.Reflection.TargetInvocationException)
error MT1046: Additional output:    at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
error MT1046: Additional output:    at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
error MT1046: Additional output:    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
error MT1046: Additional output:    at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
error MT1046: Additional output:    at System.Activator.CreateInstance(Type type, Boolean nonPublic)
error MT1046: Additional output:    at System.Activator.CreateInstance(Type type)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.CreateValuesVisitor.Visit(ElementNode node, INode parentNode)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)

error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)

error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)

error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[LocationStepView](LocationStepView view, Type callingType)
error MT1046: Additional output:    at MyApp.Views.Onboarding.Steps.LocationStepView.InitializeComponent() in /Users/rob/source/MyApp/myapp/MyApp/obj/Debug/net8.0-ios/ios-arm64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator/Views_Onboarding_Steps_LocationStepView.xaml.sg.cs:line 22
error MT1046: Additional output:    at MyApp.Views.Onboarding.Steps.LocationStepView..ctor() in /Users/rob/source/MyApp/myapp/MyApp/Views/Onboarding/Steps/LocationStepView.xaml.cs:line 17
error MT1046: Additional output:    at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Constructor(Object obj, IntPtr* args)
error MT1046: Additional output:    at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
error MT1046: Additional output: Object reference not set to an instance of an object. (System.NullReferenceException)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.SetPropertyValue(Object xamlelement, XmlName propertyName, Object value, Object rootElement, INode node, HydrationContext context, IXmlLineInfo lineInfo)
drasticactions commented 3 days ago

The newest net8.0 and net9.0 RC2 workloads support Xcode 16. So you most likely hit a regression either in your application or in MAUI—probably MAUI, if I were to guess. Having more information about your application and the view it's crashing on would help. Also, if you could try to isolate your issue with a specific control (my guess is it's with CarouselView based on the stack trace), it would help.

error MT1046: Additional output: Object reference not set to an instance of an object. (System.NullReferenceException)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.SetPropertyValue(Object xamlelement, XmlName propertyName, Object value, Object rootElement, INode node, HydrationContext context, IXmlLineInfo lineInfo)

That stands out as a potential issue.

error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType)
error MT1046: Additional output:    at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[LocationStepView](LocationStepView view, Type callingType)
error MT1046: Additional output: Exception has been thrown by the target of an invocation. (System.Reflection.TargetInvocationException)
error MT1046: Additional output:    at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
error MT1046: Additional output:    at System.RuntimeType.CreateInstanceMono(Boolean nonPublic, Boolean wrapExceptions)
error MT1046: Additional output:    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
error MT1046: Additional output:    at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
RobTF commented 2 days ago

Hi, thanks for the reply

you most likely hit a regression either in your application or in MAUI—probably MAUI, if I were to guess.

As you suggest, it definitely can't be a regression in our app as the code has had no changes. All we've done is build the same code base under XCode 16 with the latest MAUI tools.

Having more information about your application and the view it's crashing on would help.

Of course, the view is

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:vm="clr-namespace:MyApp.ViewModels.Onboarding"
             xmlns:views="clr-namespace:MyApp.Views.Onboarding"
             xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
             x:Class="MyApp.Views.Onboarding.OnboardingPage"
             x:DataType="{x:Type vm:IOnboardingPageViewModel}"
             ios:Page.UseSafeArea="True"
             Shell.NavBarIsVisible="False"
             Shell.FlyoutBehavior="Disabled"
             Shell.TitleColor="Black">
    <CarouselView
        IsSwipeEnabled="False"
        ItemsSource="{Binding Steps}"
        CurrentItem="{Binding CurrentStep}">
        <CarouselView.ItemTemplate>
            <views:OnboardingStepDataTemplateSelector />
        </CarouselView.ItemTemplate>
    </CarouselView>
</ContentPage>

I'll try to find time tonight to work on doing research and building an isolated case.

The data template selector looks like this;

namespace MyApp.Views.Onboarding;

using System;
using MyApp.ViewModels.Onboarding.Steps;
using MyApp.Views.Onboarding.Steps;

public class OnboardingStepDataTemplateSelector : DataTemplateSelector
{
    private readonly DataTemplate _welcomeStepTemplate = new(typeof(WelcomeStepView));
    private readonly DataTemplate _locationStepTemplate = new(typeof(LocationStepView));
    private readonly DataTemplate _activityStepTemplate = new(typeof(ActivityStepView));
    private readonly DataTemplate _notificationStepTemplate = new(typeof(NotificationStepView));
    private readonly DataTemplate _microphoneStepTemplate = new(typeof(MicrophoneStepView));
    private readonly DataTemplate _completedStepTemplate = new(typeof(CompletedStepView));

    protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
    {
        return item switch
        {
            IWelcomeStep => _welcomeStepTemplate,
            ILocationStep => _locationStepTemplate,
            IActivityStep => _activityStepTemplate,
            INotificationStep => _notificationStepTemplate,
            IMicrophoneStep => _microphoneStepTemplate,
            ICompletedStep => _completedStepTemplate,
            _ => throw new ArgumentException("Unknown or unsupported onboarding step type.", nameof(item)),
        };
    }
}

The "Location Step View" mentioned in the stack trace is;

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:vmo="http://myapp.com/schemas/2023/mobile/all"
             xmlns:vm="clr-namespace:MyApp.ViewModels.Onboarding.Steps"
             xmlns:vmg="clr-namespace:MyCompany.Maui.Graphics;assembly=MyCompany.Maui.Graphics"
             xmlns:obctrl="clr-namespace:MyApp.Controls.Onboarding"
             xmlns:skia="clr-namespace:SkiaSharp.Extended.UI.Controls;assembly=SkiaSharp.Extended.UI"
             x:DataType="{x:Type vm:ILocationStep}"
             x:Class="MyApp.Views.Onboarding.Steps.LocationStepView">
    <ContentView.Resources>
        <Style TargetType="Label">
            <Setter Property="HorizontalTextAlignment" Value="Center" />
            <Setter Property="FontAutoScalingEnabled" Value="False" />
        </Style>
    </ContentView.Resources>
    <VerticalStackLayout VerticalOptions="Center">
        <AbsoluteLayout>
            <VerticalStackLayout AbsoluteLayout.LayoutFlags="WidthProportional,PositionProportional">
                <AbsoluteLayout.LayoutBounds>
                    <OnIdiom Tablet="0.5,0.5,0.5,-1" Phone="0,0,1,-1" />
                </AbsoluteLayout.LayoutBounds>
                <obctrl:OnboardingStepTitle Text="{vmo:Translate LocationStep_Title, ResourceSet=OnboardingStrings}" />
                <skia:SKLottieView
                    HeightRequest="170"
                    VerticalOptions="Start"
                    HorizontalOptions="FillAndExpand"
                    RepeatMode="Restart"
                    RepeatCount="-1"
                    Source="{vmg:Animation location.json}"/>
                <StackLayout Margin="10,10,10,0" Spacing="10">
                    <Label Text="{vmo:Translate LocationStep_Body, ResourceSet=OnboardingStrings}" />
                    <Label Text="{vmo:Translate LocationStep_MoreInfo, ResourceSet=OnboardingStrings}" />
                </StackLayout>

                <obctrl:OnboardingButtonBar IsSkipVisible="{OnPlatform iOS=False, Default=True}" SkipCommand="{Binding ParentViewModel.NextStepCommand}" Margin="10,10,10,0">
                    <obctrl:OnboardingButtonBar.Options>
                        <obctrl:OnboardingButton Title="{vmo:Translate Continue_Button, ResourceSet=OnboardingStrings}" Command="{Binding AllowPermissionCommand}" />
                        <obctrl:OnboardingButton Title="{vmo:Translate LocationStep_MoreInfo_Button, ResourceSet=OnboardingStrings}" Command="{Binding MoreInformationCommand}" />
                    </obctrl:OnboardingButtonBar.Options>
                </obctrl:OnboardingButtonBar>
            </VerticalStackLayout>
        </AbsoluteLayout>
    </VerticalStackLayout>
</ContentView>

Of course this is still only partial as the whole thing spiders out into converters, markup extensions etc. etc. If it helps I'm happy to jump on a Teams call and show someone on the MAUI team the problem in-situ.

This is also why creating an isolated case takes time. I'm going to have to spend more of the weekend chopping up our fairly complex app to try to build this example to get to a point where you guys can even start to look at it, all the while there's pressure by customers to fix and publish what should be a simple problem. Unfortunately the wider business and our customers don't care that MAUI might have regressions in XCode 16 - they just question why the competitor doesn't have this problem. From a business perspective it might become faster and more cost efficient for us to give up trying to sort this now and instead try to get the old MacBook repaired.

Is there a way we can turn that stack trace into something useful? For example it mentions object reference errors, but what are they? What were the surrounding values? Can I break into this crash and investigate it in VS Code (bearing in mind that on this MacOS 15 machine breakpoints aren't working at all yet???) The stack trace itself isn't useful, its the data being used at the time of execution we need. How would one debug such a fault? how do the MAUI team do this?

RobTF commented 2 days ago

Ok, so I'm trying to diagnose this further and I'm getting wildly varying results simply from running the app.

If I run the app three times under the debugger I can end up with;

Running without debugger always results in;

It's simply undebuggable with the tools I have at my disposal as the execution is wildly inconsistent.

This is becoming critical for us. Does Microsoft offer any paid MAUI support options we can investigate?

RobTF commented 1 day ago

Hi, we managed to downgrade the MacBook from MacOS Sequoia to MacOS Sodomizer and install XCode 15.4. On top of that we loaded version 8.0.402 of the .NET MAUI workload onto the MacBook.

All of this has got us to a point where we can squeeze out a build and get it to TestFlight. If testing goes well the critical nature of our situation will be resolved for now.

I have noticed however that running the app from VS Code either with or without the debugger causes the app to hang within 10 seconds about 9 times out of 10, if it doesn't hang within those first 10 seconds it runs fine with the debugger attached. The app never hangs when the debug build is run from the iOS device itself by tapping the icon, and the TestFlight/production builds do not exhibit this problem. This makes debugging a real pain (think going back to the old printf() style debugging methods) but thankfully is a non-production problem.

If I get time to mess about with XCode 16 I'll take another look. Again, happy to work directly with the MAUI team showing our app etc. but other than that, due to time, we'll likely just hunker down with a working toolchain and hope that by the third or fourth release of MAUI for .NET 9 that this is all mostly sorted and attempt to upgrade things again then.

dotnet-policy-service[bot] commented 1 day ago

Hi @RobTF. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

PureWeen commented 1 day ago

We have some new opt-in handlers for NET9

https://github.com/dotnet/maui/issues/25248

Once you're on RC2 for NET9 I'd be curious to know if you are still seeing the issue

dotnet-policy-service[bot] commented 23 hours ago

Hi @RobTF. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.