-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix: Null Reference Exception in ShellContentFragment.Destroy #29713
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
base: main
Are you sure you want to change the base?
Conversation
…llContentFragment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a null reference exception occurring in the ShellContentFragment.Destroy method on Android by adding a null-conditional operator.
- Updates the observer removal call to handle a potentially null _shellContext.
Comments suppressed due to low confidence (1)
src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellContentFragment.cs:176
- Using the null-conditional operator bypasses the observer removal if _shellContext is null. Please confirm that skipping the removal in such cases is an intentional design decision and does not lead to lingering observers.
((IShellController)_shellContext?.Shell)?.RemoveAppearanceObserver(this);
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using "as" seems better in this case.
Can we add a test?
@@ -173,7 +173,7 @@ void Destroy() | |||
// to avoid the navigation `TaskCompletionSource` to be stuck forever. | |||
AnimationFinished?.Invoke(this, EventArgs.Empty); | |||
|
|||
((IShellController)_shellContext.Shell).RemoveAppearanceObserver(this); | |||
((IShellController)_shellContext?.Shell)?.RemoveAppearanceObserver(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
((IShellController)_shellContext?.Shell)?.RemoveAppearanceObserver(this); | |
(_shellContext?.Shell as IShellController)?.RemoveAppearanceObserver(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rmarinho Great suggestion on the as
.
Regarding the test: I'd love to but, I can't find any existing tests around this, do you have any suggestions on how to test this scenario?
Thanks!
@rmarinho, @jsuarezruiz, @StephaneDelcroix or @tj-devel709 What can we do to help get this moving? Our app is seeing increased problems as a result of this root issue so we'd really like to get it solved. It doesn't appear most of the checks on the PR ever reported in—how can those be restarted? |
We have experienced this issue as well in our first .NET 9/MAUI app release 10 days ago. |
I believe that this is what needs to be done: #29713 (review) |
@MartyIX I asked for help on the testing here: #29713 (comment). I wasn't sure how to test it and couldn't find any existing tests around that behavior to modify. Would appreciate some help in that area if someone has the expertise. |
@jsuarezruiz @rmarinho Would you help with the test please? |
Yes, let me assigned to the PR to include tests. |
/rebase |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
@postalservice14 Could you try adding something like?
Here:
|
@dotnet-policy-service agree company="Ramsey Solutions" |
Commenter does not have sufficient privileges for PR 29713 in repo dotnet/maui |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Running the failed Android UITest again, but is not related with the changes. |
@@ -173,7 +173,7 @@ void Destroy() | |||
// to avoid the navigation `TaskCompletionSource` to be stuck forever. | |||
AnimationFinished?.Invoke(this, EventArgs.Empty); | |||
|
|||
((IShellController)_shellContext.Shell).RemoveAppearanceObserver(this); | |||
(_shellContext?.Shell as IShellController)?.RemoveAppearanceObserver(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add a check on this destroy method so that it only runs once?
It's fine to leave this code but I just worry that this destroy method is being called twice which might just manifest as a different problem down the road
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check it.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description of Change
This PR fixes a null reference exception in the ShellContentFragment.Destroy method for Android. The issue occurred when attempting to call RemoveAppearanceObserver on a possibly null ShellContext. The fix adds a null-conditional operator to safely access ShellContext before invoking the method.
Issues Fixed
Fixes #29712