Skip to content

System.NullReferenceException at NavigationRenderer.SetStatusBarStyle() #29535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MateusMiotto opened this issue May 15, 2025 · 8 comments · May be fixed by #29564
Open

System.NullReferenceException at NavigationRenderer.SetStatusBarStyle() #29535

MateusMiotto opened this issue May 15, 2025 · 8 comments · May be fixed by #29564
Labels
area-navigation NavigationPage high It doesn't work at all, crashes or has a big impact. platform/ios potential-regression This issue described a possible regression on a currently supported version., verification pending s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@MateusMiotto
Copy link

MateusMiotto commented May 15, 2025

Description

After migrating from .net8 to .net9 this issue appeared.
After navigating from a login screen to the app's home page, which does not have a status bar, I receive a System.NullReferenceException

[0:] * Unhandled Exception *: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.SetStatusBarStyle()
   at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.ViewWillAppear(Boolean animated)
   at Microsoft.Maui.Controls.Handlers.Compatibility.NavigationRenderer.__Registrar_Callbacks__.callback_1068_Microsoft_Maui_Controls_Handlers_Compatibility_NavigationRenderer_ViewWillAppear(IntPtr pobj, IntPtr sel, Byte p0, IntPtr* exception_gchandle)
--- End of stack trace from previous location ---
   at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 2742
   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
   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 App.Program.Main(String[] args) in C:\dev\App\Platforms\iOS\Program.cs:line 16

I am using NavigationPage.HasNavigationBar as false at HomePage but using it as true did not throw an exception in my tests
The Home page is a FlyoutPage and the details is the page with the tag NavigationPage.HasNavigationBar
This crash happens only when i try to navigate from login page to home page, if the application starts directly in that, the exception doesn't happens, using NavigationPage.HasNavigationBar as true or false.

Image

Steps to Reproduce

I don't know exactly the reason of that, so, don't have a sample

Link to public reproduction project repository

No response

Version with bug

9.0.70 SR7

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.80 SR8

Affected platforms

iOS

Affected platform versions

iOS only

Did you find any workaround?

Nop

Relevant log output

@MateusMiotto MateusMiotto added the t/bug Something isn't working label May 15, 2025
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

@PureWeen
Copy link
Member

PureWeen commented May 15, 2025

Can you extract out something into a repro? That direct code hasn't changed in a number of years so it's hard to say.

NET9 does cleanup code a bit more aggressively than NET8 did so I'm guessing that's related

@PureWeen PureWeen added high It doesn't work at all, crashes or has a big impact. platform/iOS s/needs-info Issue needs more info from the author area-navigation NavigationPage labels May 15, 2025
@MateusMiotto
Copy link
Author

For me, the exception does not happen in all reproductions, it is something almost random.

I am not using shell for navigation.

I can describe that I have a Login screen for the tenant, I create a navigation stack for another user login screen.

When the login is successful I need to replace the app's mainPage with a Flyout Page that contains the menu items and the Details screen.

I know this is not the best way to do it, but using Navigation I did not get the desired behavior.

Only in this specific situation I replace:

Application.Current.Windows[0].Page = page;

When the app is closed and opened again, if the user is already logged in, I directly assign the MainPage as my Flyout once. This does not cause any exceptions, only if my home page is not instantiated at all.

Explanation:
If I open the app on the Home screen, log out (go to login), log in again, the exception does not occur even when using

Application.Current.Windows[0].Page = page;

Because the HomePage was already created one time. This seems like just a coincidence, but it was noticed.

I can't say that this is what is causing the error.

I confess that this situation is making me lose my hair.

I am available for any information and help needed.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels May 16, 2025
@kubaflo
Copy link
Contributor

kubaflo commented May 17, 2025

@PureWeen can you please /azp, so that @MateusMiotto can try if this PR fixes it

@PureWeen
Copy link
Member

@PureWeen can you please /azp, so that @MateusMiotto can try if this PR fixes it

@MateusMiotto where you able to try the nugets from @kubaflo 's PR?

@PureWeen PureWeen added the potential-regression This issue described a possible regression on a currently supported version., verification pending label May 20, 2025
@PureWeen PureWeen added this to the .NET 9 Servicing milestone May 20, 2025
@MateusMiotto
Copy link
Author

This fix is avaliable in any published version?

@kubaflo
Copy link
Contributor

kubaflo commented May 20, 2025

This fix is avaliable in any published version?

@MateusMiotto No, it isn't. We would like you to test this pr: #29564 according to these docs: https://github.com/dotnet/maui/wiki/Testing-PR-Builds

It is because we want to know if the changes fix your crash since you did not attach any repro and we cannot reproduce it

@MateusMiotto
Copy link
Author

I followed the tutorial link and spent a few hours today to test this fix and it worked fine, the exception doesn't happen anymore.

@anandhan-rajagopal anandhan-rajagopal added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed and removed s/needs-attention Issue has more information and needs another look labels May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-navigation NavigationPage high It doesn't work at all, crashes or has a big impact. platform/ios potential-regression This issue described a possible regression on a currently supported version., verification pending s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants