Maui
Maui copied to clipboard
[BUG] StatusBarBehavior.SetAppThemeColor(...) throws NullReferenceExceptions on MAUI Nightly builds
Is there an existing issue for this?
- [X] I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- [X] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
When calling statusBarBehavior.SetAppThemeColor(StatusBarBehavior.StatusBarColorProperty, Color.FromRgb(255, 0, 0), Color.FromRgb(0, 255, 0));, my app crashes with a NullReferenceException, with the last line in the stacktrace being:
at Microsoft.Maui.Controls.AppThemeBinding.AppThemeProxy..ctor(Element parent, AppThemeBinding binding)
Since this currently occurs only with the MAUI nightly builds and contains the word "AppThemeProxy", I suspect it has something to do with this recent PR in the MAUI repository.
Expected Behavior
I would hope to still be able to set the status bar color in my iOS App.
Steps To Reproduce
- Open and run solution from the reproduction project on the iOS simulator
- The solution will crash on line 17 of AppShell.xaml.cs while trying to call
statusBarBehavior.SetAppThemeColor - The topmost lines of the stacktrace should look like this:
System.NullReferenceException: Object reference not set to an instance of an object
at Microsoft.Maui.Controls.AppThemeBinding.AppThemeProxy..ctor(Element parent, AppThemeBinding binding)
at Microsoft.Maui.Controls.AppThemeBinding.Apply(Object context, BindableObject bindObj, BindableProperty targetProperty, Boolean fromBindingContextChanged, SetterSpecificity specificity)
at Microsoft.Maui.Controls.BindableObject.SetBinding(BindableProperty targetProperty, BindingBase binding, SetterSpecificity specificity)
at Microsoft.Maui.Controls.BindableObject.SetBinding(BindableProperty targetProperty, BindingBase binding)
at Microsoft.Maui.Controls.BindableObjectExtensions.SetAppTheme[Color](BindableObject self, BindableProperty targetProperty, Color light, Color dark)
at Microsoft.Maui.Controls.BindableObjectExtensions.SetAppThemeColor(BindableObject self, BindableProperty targetProperty, Color light, Color dark)
at AppThemeCrash.AppShell.OnBindingContextChanged() in /Users/user1/TestApp/TestApp/AppShell.xaml.cs:line 41
- Set the <MauiVersion>-tag in the *.csproj back to the latest stable version (8.0.14) and restart the application
- No error anymore
Link to public reproduction project repository
https://github.com/DDHSchmidt/AppThemeCrash
Environment
- .NET MAUI CommunityToolkit: 7.0.1
- OS: iOS 17.2
- .NET MAUI: 8.0.20-nightly.10376+sha.402fdf7fcc-azdo.9307199
Anything else?
I suspect PR #21229 to likely be the cause of this crash