CommunityToolkit / Maui

The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier
https://learn.microsoft.com/dotnet/communitytoolkit/maui
MIT License
2.29k stars 404 forks source link

[BUG] CommunityToolkit.Maui.Core.Platform.StatusBar causes app to fail on iOS Testflight #1374

Open needledrag opened 1 year ago

needledrag commented 1 year ago

Is there an existing issue for this?

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

I've tested my .net Maui app in Android and iOS, debug, release and on device, Android now in Closed Testing on Google Play. Just uploaded to App Connect and testing on a device using TestFlight.

On both devices I get the error in appcenter as the app loads the splash screen and goes blank:

  "exception": {
    "type": "System.InvalidOperationException",
    "message": "RootViewController cannot be null",
    "stackTrace": "   at CommunityToolkit.Maui.Core.Platform.StatusBar.UpdateStatusBarAppearance(UIWindow window)\n   at CommunityToolkit.Maui.Core.Platform.StatusBar.PlatformSetColor(Color color)\n   at CommunityToolkit.Maui.Core.Platform.StatusBar.SetColor(Color color)\n   at CommunityToolkit.Maui.Behaviors.StatusBarBehavior.OnPropertyChanged(String propertyName)\n   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)\n   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)\n   at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value, Boolean fromStyle, Boolean checkAccess)\n   at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value)\n   at CommunityToolkit.Maui.Behaviors.StatusBarBehavior.set_StatusBarColor(Color value)\n   at InkflowApp.Views.Base.PageBase.InitializeComponent()\n   at InkflowApp.Views.Base.PageBase..ctor()\n   at InkflowApp.Views.Base.ViewBase`1[[InkflowApp.ViewModels.Home.IntroViewModel, InkflowApp, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null]]..ctor()\n   at InkflowApp.Views.Home.IntroView..ctor()\n   at InkflowApp.ViewModels.Home.InitViewModel.OnNavigatedTo(Object parameters)",
    "wrapperSdkName": "appcenter.xamarin"
  }

I have the following code in my PageBase which every page is based off <Page.Behaviors> <mct:StatusBarBehavior StatusBarColor="{StaticResource AppPrimaryBGColour}" StatusBarStyle="DarkContent"/> </Page.Behaviors>

I've read in the MS docs that this should be set in Behaviors as putting it in the class constructor or OnNavigatedTo (or OnAppearing) can cause problems if platform specific components haven't been initialised.

As I mentioned, this works in debug, on device and in release mode for both Android an iOS and published in Android, it just seems to be on publishing the iOS app this occurs every time.

Expected Behavior

Statusbar colour is set and app proceeds as expected to load the page.

Steps To Reproduce

As everything works in dev and release you'd need to depoly an app to the App Connect and test in Test Flight as this seems to be the only place I can reproduce it.

Link to public reproduction project repository

Unable to reproduce except in Test Flight

Environment

- .NET MAUI CommunityToolkit: 5.3
- OS: iOS 14.4.2
- .NET MAUI: 7

Anything else?

Any help or known workaround would be greatly appreciated.

ghost commented 1 year ago

Hi @needledrag. We have added the "needs reproduction" label to this issue, which indicates that we cannot take further action. This issue will be closed automatically in 5 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.

pictos commented 1 year ago

@needledrag can you reproduce this using release mode, with the same configurations that you use to build the test flight app?

needledrag commented 1 year ago

Unfortunately not, it all works in release mode and even on a connected device. It's only when I install a published build from App Connect that this occurs. I've even tried to install on the same device that it worked on when testing the release mode and it fails. If all else fails I guess I could change the info.plist and set the Status bar style there directly?

pictos commented 1 year ago

@needledrag is your app using TabPage or Shell?

needledrag commented 1 year ago

Shell

pictos commented 1 year ago

@needledrag for now, you can try to set the value on info.plist, probably it's caused by some issue around the initialization. This was working before?

needledrag commented 1 year ago

It works in all other environments and on an Android published app but this is the first time I've published the iOS app to App Connect.

evgenyKozlov1996 commented 10 months ago

Verified the issue. Visual Studio 2022 v17.8.5 .NET MAUI 8 CommunityToolkit v7.0.1 iOS 17.3 IPhone 13 Pro Max

Steps to reproduce:

P.S.: Maybe this issue is related to using ReactiveUI for MAUI

needledrag commented 10 months ago

I had to remove the toolkit StatusBarBehavior for iOS builds to get around this

bijington commented 10 months ago

Verified the issue.

Visual Studio 2022 v17.8.5

.NET MAUI 8

CommunityToolkit v7.0.1

iOS 17.3

IPhone 13 Pro Max

Steps to reproduce:

  • Build iOS Debug version and deploy it to the real device.

  • App will be opened successfully.

  • Close the app and detach the debugger.

  • Open the app from IPhone. App will show loading screen and crash when trying to open the first page.

P.S.: Maybe this issue is related to using ReactiveUI for MAUI

If you follow the same steps with the sample app do you see the same crash?

canmjp1 commented 7 months ago

I am experiencing the same thing. Has there been a fix for this yet?

AndrewMiller34 commented 7 months ago

Verified the issue. Visual Studio 2022 17.10.0 Preview 2.0 NET MAUI 8 CommunityToolkit v7.0.1 iOS 17.4.1 iPhone 12

Steps to reproduce:

When I try to add the behavior in the xaml.cs instead, it actually gives me a warning saying it's unsupported for iOS and Windows; but the docs are not agreeing.

I've included the required info.plist key according to the docs: `

UIViewControllerBasedStatusBarAppearance

`

Works fine for Android and while debugging. But whether it's a Release or Debug build it will not run on the physical iPhone without the debugger attached.

Blinchik91 commented 6 months ago

same here, still not fixed or working with .NET 8 and SimpleToolkit.SimpleShell in my case. If I remove the StatusbarBehavior it works like mentioned

I had to remove the toolkit StatusBarBehavior for iOS builds to get around this

thedee commented 5 months ago

I am also getting the error doing this on the constructor on a ContentPage:

this.Behaviors.Add(new StatusBarBehavior
{
    StatusBarColor = ColorResources.HeaderColor
});

Works fine when debugging but it errors when doing an Ad-Hoc build and installing it through iTunes on the device.

canmjp1 commented 5 months ago

My workaround for this was adding this to the App OnStart()

CommunityToolkit.Maui.Core.Platform.StatusBar.SetColor(Color.FromArgb("#1190ca")); CommunityToolkit.Maui.Core.Platform.StatusBar.SetStyle(CommunityToolkit.Maui.Core.StatusBarStyle.LightContent);

eddieyanez commented 4 months ago

I've had this issue when using the behaviour directly on AppShell.xaml rather than on the ContentPage. To fix that, I've applied the behaviour to the pages rather than shell.

lhughey commented 4 months ago

Experiencing this issue ONLY on the first startup page. Pages that are navigated to from that beginning page are working fine. Odd.

AmaluThomas commented 4 months ago

I've had this issue when using the behaviour directly on AppShell.xaml rather than on the ContentPage. To fix that, I've applied the behaviour to the pages rather than shell.

Even in contentpage on release mode it crashes that is in testflight.

Is there any other solution?

AmaluThomas commented 4 months ago

My workaround for this was adding this to the App OnStart()

CommunityToolkit.Maui.Core.Platform.StatusBar.SetColor(Color.FromArgb("#1190ca")); CommunityToolkit.Maui.Core.Platform.StatusBar.SetStyle(CommunityToolkit.Maui.Core.StatusBarStyle.LightContent);

Are you able to upload to testflight without any crash?

AmaluThomas commented 4 months ago

Fixed the status bar issues and was successfully able to build app:

(https://learn.microsoft.com/en-us/answers/questions/1341985/net-maui-how-to-change-status-bar-and-navigation-b)

mackayn commented 4 months ago

Noticed this as well in Release mode in iOS, the first page navigation will crash with the attached status bar behavior. Cobbled together this workaround as I only wanted to set the set the color once, it sets the status bar more than once but need something quick that was reliable, This is a MAUI app that doesn't use shell.

    public partial class AppNavigationPage
    {
        private bool _isRendered;

        public AppNavigationPage()
        {
            InitializeComponent();
        }

        protected override void OnHandlerChanged()
        {
            base.OnHandlerChanged();
            RepaintStatusBar();
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();
            RepaintStatusBar();
            _isRendered = true;
        }

        protected override void OnSizeAllocated(double width, double height)
        {
            base.OnSizeAllocated(width, height);
            if (_isRendered)
            {
                RepaintStatusBar();
            }
        }

#if IOS
        private static void UpdateStatusBarAppearance(UIWindow? window)
        {
            var vc = window?.RootViewController ?? WindowStateManager.Default.GetCurrentUIViewController();
            if (vc != null)
            {
                while (vc.PresentedViewController is not null)
                {
                    vc = vc.PresentedViewController;
                }

                vc.SetNeedsStatusBarAppearanceUpdate();
            }
        }
#endif
        private void RepaintStatusBar()
        {
#if IOS
            var statusBarTag = new IntPtr(38482);
            if (GetParentWindow()?.Handler?.PlatformView is UIWindow window)
            {
                var topPadding = window?.SafeAreaInsets.Top ?? 0;

                var statusBar = new UIView(new CoreGraphics.CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, topPadding))
                {
                    BackgroundColor = ResourceHelper.GetNamedResourceColor("NavigationBarBackgroundColor").ToPlatform(),
                    Tag = statusBarTag,
                };

                var statusBarSubViews = window.Subviews.Where(x => x.Tag == statusBarTag).ToList();
                foreach (var statusBarSubView in statusBarSubViews)
                {
                    statusBarSubView.RemoveFromSuperview();
                }

                window.AddSubview(statusBar);

                UpdateStatusBarAppearance(window);
            }
#endif
        }
    }
vhugogarcia commented 4 months ago

Thanks @mackayn and @AmaluThomas for sharing your results and workarounds.

It is hard for us to reproduce this issue by using the MCT sample app. If we run the sample app on DEBUG or RELEASE mode everything works as expected. However, @needledrag mentioned it only fails when the app is published to TestFlight on iOS.

If it is possible from any participant on this issues to share here the Error Stack Trace, maybe from Sentry or Firebase Crashlytics or any other third party error handler service that give us more insights will be fantastic, please.

I'm closing this issue for now. We can re-open it if needed in the future.

Confusedfish commented 3 months ago

I too am hitting this problem in that using the StatusBarBehaviour works as expected in debug but all production builds crash on startup on both Android and iOS. Using a local release build does not have the same problem, it only happens after the build and packaging process.

I am using:

The stack trace captured on iOS is as follows:

System.NotSupportedException: PlatformSetColor is only supported on iOS and Android 23 and later at CommunityToolkit.Maui.Core.Platform.StatusBar.SetColor(Color color) at CommunityToolkit.Maui.Behaviors.StatusBarBehavior.OnPropertyChanged(String propertyName) at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value)

I note that the exception text comes from StatusBar.net.cs not StatusBar.ios.cs. Could this be a packaging issue? I am not sure why StatusBar.net.cs would be being included on an Android / iOS build.

If I copy out the relevant code from StatusBar.Android.cs and StatusBar.ios.cs into my own solution and use that code to change the status bar color then I have no problems.

How can I help diagnose this problem?

mackayn commented 3 months ago

Not sure why this one was closed, all you have to do is compile the iOS client in release config and it'll explode the app, I don't know if it applies the styling too early, the handler events can be a little unreliable.

Confusedfish commented 3 months ago

Not sure why this one was closed, all you have to do is compile the iOS client in release config and it'll explode the app, I don't know if it applies the styling too early, the handler events can be a little unreliable.

That's strange. I could compile a release build and deploy to a local device and not get the exception. What version of the NuGet are you on when you get the problem?

bijington commented 3 months ago

A duplicate issue was recently closed because updates to VS solved the issue: https://github.com/CommunityToolkit/Maui/issues/2136 it might help?

mackayn commented 3 months ago

Not sure why this one was closed, all you have to do is compile the iOS client in release config and it'll explode the app, I don't know if it applies the styling too early, the handler events can be a little unreliable.

That's strange. I could compile a release build and deploy to a local device and not get the exception. What version of the NuGet are you on when you get the problem?

9.0.2.

Confusedfish commented 3 months ago

I do get slightly different behaviour on 9.0.3 relating to supporting the transparent status bar. Do you get the same problem even on the latest NuGet?

mackayn commented 3 months ago

I tested against artifacts built in release config on macOS13 via devops pipelines, I've worked around it in two slightly different ways on 2 different apps via a dependency service and the workaround above in the nav page.

bijington commented 3 months ago

@Confusedfish that is very interesting! I Out of interest are you building a single project app or do you have class libraries also within your solution? I am just trying to determine how the target of net8.0 might be used over net8.0-ios

LeoJHarris commented 3 months ago

My workaround for this was adding this to the App OnStart()

CommunityToolkit.Maui.Core.Platform.StatusBar.SetColor(Color.FromArgb("#1190ca")); CommunityToolkit.Maui.Core.Platform.StatusBar.SetStyle(CommunityToolkit.Maui.Core.StatusBarStyle.LightContent);

This was the only solution that worked for me, anywhere else always crashed the app on iOS irrespective whether it was Debug, Ad-hoc or AppStore configs.

AmaluThomas commented 3 months ago

Please add these line of code in Appshell page

    public AppShell()
    {
        InitializeComponent();

if IOS

        WeakReferenceMessenger.Default.Register<ColorChangedMessage>(this, (r, m) =>
            {
                var color = m.Value as Color;
                SetTabBarBackgroundColor(this, color);
                SetBackgroundColor(this, color);
            }); 

endif

And add this line of code to the xaml.cs file (ContentPage) OnAppearing()

if IOS

        WeakReferenceMessenger.Default.Send<ColorChangedMessage>(new ColorChangedMessage(Color.FromArgb("#e3f542"))); 

endif

This will solve the issue

LeoJHarris commented 3 months ago

@AmaluThomas we don't use Shell but that can go into any other Page?

AmaluThomas commented 3 months ago

@LeoJHarris No, as they are AppShell.SetTabBarBackgroundColor and AppShell.SetBackgroundColor. This is context from appshell

mackayn commented 3 months ago

@LeoJHarris No, as they are AppShell.SetTabBarBackgroundColor and AppShell.SetBackgroundColor. This is context from appshell

This only applies to shell which a lot of production MAUI apps won't be using.

Confusedfish commented 3 months ago

@Confusedfish that is very interesting! I Out of interest are you building a single project app or do you have class libraries also within your solution? I am just trying to determine how the target of net8.0 might be used over net8.0-ios

Problem resolved by upgrading to dotnet 8.0.400 on build agent

There are project class libraries referenced in the MAUI app which is then compiled with the following target frameworks: <TargetFrameworks>net8.0-android; net8.0-ios</TargetFrameworks>

The project is then built using an Azure Pipeline on a self hosted Mac build agent using the command dotnet publish -f net8.0-ios -c $(BuildConfig) -p:Version=$(Build.BuildNumber) and then again for Android using dotnet publish -f net8.0-android -c $(BuildConfig) -p:Version=$(Build.BuildNumber)

The issue #2136 suggests upgrading VS but the build agent is on VS for Mac 17.6.14 and the build is performed using dotnet and the build agent is on the latest version of VS for Mac already. The project already uses a higher version if MAUI than suggested in that issue.

I had got around the problem by copying the source code out of this repo and placing it directly in my solution. I had already tried the various suggested workarounds in this thread including the WeakReferenceMessenger approach. They all had the same result of crashing on startup.

Following the suggestion in #2136 of upgrading VS I thought I would check which version of dotnet was being used by the pipeline. It was set to use 8.0.100 so I updated it to use 8.0.400 and rebuilt. The problem has now gone away and I have reverted to using the much simpler approach of markup in the XAML:

<Page.Behaviors>
    <toolkit:StatusBarBehavior StatusBarColor="Transparent" StatusBarStyle="LightContent" ApplyOn="OnPageNavigatedTo" />
</Page.Behaviors>
mackayn commented 3 months ago

@Confusedfish that is very interesting! I Out of interest are you building a single project app or do you have class libraries also within your solution? I am just trying to determine how the target of net8.0 might be used over net8.0-ios

Problem resolved by upgrading to dotnet 8.0.400 on build agent

There are project class libraries referenced in the MAUI app which is then compiled with the following target frameworks: <TargetFrameworks>net8.0-android; net8.0-ios</TargetFrameworks>

The project is then built using an Azure Pipeline on a self hosted Mac build agent using the command dotnet publish -f net8.0-ios -c $(BuildConfig) -p:Version=$(Build.BuildNumber) and then again for Android using dotnet publish -f net8.0-android -c $(BuildConfig) -p:Version=$(Build.BuildNumber)

The issue #2136 suggests upgrading VS but the build agent is on VS for Mac 17.6.14 and the build is performed using dotnet and the build agent is on the latest version of VS for Mac already. The project already uses a higher version if MAUI than suggested in that issue.

I had got around the problem by copying the source code out of this repo and placing it directly in my solution. I had already tried the various suggested workarounds in this thread including the WeakReferenceMessenger approach. They all had the same result of crashing on startup.

Following the suggestion in #2136 of upgrading VS I thought I would check which version of dotnet was being used by the pipeline. It was set to use 8.0.100 so I updated it to use 8.0.400 and rebuilt. The problem has now gone away and I have reverted to using the much simpler approach of markup in the XAML:

<Page.Behaviors>
    <toolkit:StatusBarBehavior StatusBarColor="Transparent" StatusBarStyle="LightContent" ApplyOn="OnPageNavigatedTo" />
</Page.Behaviors>

Thanks for posting this, our pipelines use SDK 8.0.204 so that may well be the issue. May be worth mentioning in the usage of the control that you need to build against this SDK in release mode.

ronanj2 commented 3 months ago

Seeing the same issue on opening the first page. Release mode, installed from TestFlight. https://moz-1e.sentry.io/share/issue/c9b6270725ad4a1a9bc7dfcb6e416874/

bijington commented 3 months ago

The biggest confusion is still the source of where the exception is thrown in our codebase - it comes from the .net.cs file not .ios.cs which makes me believe that for some reason when your app is compiled you are somehow getting the net version and not the ios version.

So to return to an earlier question, where are people using this behavior? Is it in the app project or a class library project? And if it is the latter how is that targeted (e.g. net8.0, net8.0-ios, etc.)?

Confusedfish commented 3 months ago

@bijington I get this problem in the app project but only if I compile the solution with dotnet 8.0.100. On >= 8.0.400 I no longer have the problem.

@ronanj2 what version of dotnet are you compiling your release?

ronanj2 commented 3 months ago

SDK Version: 8.0.401, GitHub actions hosted runner.

ronanj2 commented 3 months ago

The biggest confusion is still the source of where the exception is thrown in our codebase - it comes from the .net.cs file not .ios.cs which makes me believe that for some reason when your app is compiled you are somehow getting the net version and not the ios version.

So to return to an earlier question, where are people using this behavior? Is it in the app project or a class library project? And if it is the latter how is that targeted (e.g. net8.0, net8.0-ios, etc.)?

latter and csproj has:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">
            $(TargetFrameworks);net8.0-windows10.0.19041.0
        </TargetFrameworks>
        <Authors>...</Authors>
        <Company>...</Company>
        <Copyright>...</Copyright>

        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <MauiVersion>8.0.80</MauiVersion>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">12.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">
            13.1
        </SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
            10.0.17763.0
        </SupportedOSPlatformVersion>
        <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
            10.0.17763.0
        </TargetPlatformMinVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
    </PropertyGroup>
Confusedfish commented 3 months ago

SDK Version: 8.0.401, GitHub actions hosted runner.

Strange, that fixed it for me

Confusedfish commented 3 months ago

@ronanj2 are you using toolkit 9.0.3?

<PackageReference Include="CommunityToolkit.Maui" Version="9.0.3" />

ronanj2 commented 3 months ago

@ronanj2 are you using toolkit 9.0.3?

<PackageReference Include="CommunityToolkit.Maui" Version="9.0.3" />

I had 9.0.2. I just ugpraded to 9.0.3 and same crash happens. https://moz-1e.sentry.io/share/issue/97b3abf58e2f45b9bdcaf45f761b8f2f/

Confusedfish commented 3 months ago

I can't help but think that this is something that I changed on our build server then as I can see no other code change that would have made a difference. Unfortunately it is offline until when I am back in the office on Tuesday but I will see if I can think of anything when I am back in the office.

MoienTajik commented 2 months ago

I have the same problem and the application crashes on iOS, even on debug mode using simulator:

App.xaml.cs:

public partial class App
{
    public App()
    {
        InitializeComponent();
    }

    protected override Window CreateWindow(IActivationState? activationState)
    {
        return new(new MainPage());
    }
}

MainPage.xaml:

<?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:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             xmlns:shared="clr-namespace:MyApplication.Client.Shared;assembly=MyApplication.Client.Shared"
             x:Class="MyApplication.Client.Mobile.MainPage"
             BackgroundColor="{DynamicResource PageBackgroundColor}">

    <ContentPage.Behaviors>
        <toolkit:StatusBarBehavior ApplyOn="OnPageNavigatedTo" StatusBarStyle="DarkContent"/>
    </ContentPage.Behaviors>

    <StackLayout VerticalOptions="FillAndExpand">
        <BlazorWebView HorizontalOptions="FillAndExpand"
                       VerticalOptions="FillAndExpand"
                       HostPage="wwwroot/index.html">
            <BlazorWebView.RootComponents>
                <RootComponent Selector="#app" ComponentType="{x:Type shared:Routes}" />
            </BlazorWebView.RootComponents>
        </BlazorWebView>
    </StackLayout>
</ContentPage>

Stacktrace:

System.InvalidOperationException: RootViewController cannot be null
   at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.SetPropertyValue(Object xamlelement, XmlName propertyName, Object value, Object rootElement, INode node, HydrationContext context, IXmlLineInfo lineInfo)
   at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.Visit(ValueNode node, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ValueNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType)
   at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[MainPage](MainPage view, Type callingType)
   at MyApplication.Client.Mobile.MainPage.InitializeComponent() in /Users/moientajik/Personal/MyApplication/src/frontend/MyApplication.Client.Mobile/obj/Debug/net9.0-ios/iossimulator-x64/Microsoft.Maui.Controls.SourceGen/Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator/MainPage.xaml.sg.cs:line 27
   at MyApplication.Client.Mobile.MainPage..ctor() in /Users/moientajik/Personal/MyApplication/src/frontend/MyApplication.Client.Mobile/MainPage.xaml.cs:line 11
   at MyApplication.Client.Mobile.App.CreateWindow(IActivationState activationState) in /Users/moientajik/Personal/MyApplication/src/frontend/MyApplication.Client.Mobile/App.xaml.cs:line 15
   at Microsoft.Maui.Controls.Application.Microsoft.Maui.IApplication.CreateWindow(IActivationState activationState)
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IApplication application, UIWindowScene windowScene, NSDictionary[] states)
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IUIApplicationDelegate platformApplication, IApplication application, UIApplication uiApplication, NSDictionary launchOptions)
   at Microsoft.Maui.MauiUIApplicationDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions)
   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 61
   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
   at MyApplication.Client.Mobile.Program.Main(String[] args) in /Users/moientajik/Personal/MyApplication/src/frontend/MyApplication.Client.Mobile/Platforms/iOS/Program.cs:line 9

Versions:

bijington commented 2 months ago

@MoienTajik please note that this issue is closed and we also do not officially support .NET 9.0 and won't until it GAs.

ronanj2 commented 2 months ago

@MoienTajik please note that this issue is closed and we also do not officially support .NET 9.0 and won't until it GAs.

Previous commentor was .NET 9 but many others (including me) are .NET 8. I posted the TFMs above.

bijington commented 2 months ago

@ronanj2 the latest crash reported in this comment https://github.com/CommunityToolkit/Maui/issues/1374#issuecomment-2308899460 looks like a threading issue on Android and not this issue