Skip to content

[BUG] StatusBarBehavior.SetAppThemeColor(...) throws NullReferenceExceptions on MAUI Nightly builds #1776

@DDHSchmidt

Description

@DDHSchmidt

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

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

  1. Open and run solution from the reproduction project on the iOS simulator
  2. The solution will crash on line 17 of AppShell.xaml.cs while trying to call statusBarBehavior.SetAppThemeColor
  3. 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
  1. Set the <MauiVersion>-tag in the *.csproj back to the latest stable version (8.0.14) and restart the application
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/behaviorsIssue/Discussion/PR that has to do with BehaviorsbugSomething isn't workingunverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions