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

Is there an existing issue for this?

  • I have searched the existing issues

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.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 5
  • Comments: 64 (18 by maintainers)

Most upvoted comments

Had the same problem (PlatformSetStyle is only supported on iOS and Android 23 and later), downgrade to 9.0.3 was the (temporary) solution!

Even had problems with Keyboard extension methods: NotSupportedException on HideKeyboardAsync and ShowKeyboardAsync.

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);

I was having the same exception message. System.NotSupportedException: PlatformSetColor is only supported on iOS and Android 23 and later My workaround: Downgrade MAUI Community Toolkit from 9.1.0 to 9.0.3. Hope this helps!

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

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

That’s not the same as this issue reports. This issue specifically reports an exception being reported. Can you please raise a separate issue so we can track it?

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

@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>

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.

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

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:

  • CommunityToolkit.Maui 9.0.3
  • CommunityToolkit.Mvvm 8.2.2
  • Microsoft.Maui.Controls 8.0.80
  • Microsoft.Maui.Controls.Compatibility 8.0.80

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?

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

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