Fix for exception thrown when disconnecting page handlers in the Unloaded event while navigating on MacCatalyst and iOS#29410
Merged
PureWeen merged 8 commits intodotnet:inflight/currentfrom Sep 10, 2025
Conversation
jsuarezruiz
previously requested changes
May 9, 2025
| @@ -0,0 +1,27 @@ | |||
| #if !ANDROID | |||
| //Skipping the test case to run in android because the loaded event is not triggered when navigating back to previous page. | |||
Contributor
There was a problem hiding this comment.
Could you create a new bug and include the link to it here?
Contributor
Author
There was a problem hiding this comment.
I have logged new bug report for this issue.
#29414
Contributor
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
rmarinho
reviewed
May 10, 2025
Member
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
PureWeen
requested changes
Jun 2, 2025
| _loadedUnloadedToken?.Dispose(); | ||
| _loadedUnloadedToken = null; | ||
| _loadedUnloadedToken = this.OnLoaded(SendLoaded); | ||
| if (Handler is not null) |
Member
There was a problem hiding this comment.
Can you also add the check for window?
Window?.Handler?.PlatformView
Contributor
Author
There was a problem hiding this comment.
Can you also add the check for window?
Window?.Handler?.PlatformView
The user is disconnecting the page handler during the Unloaded event. If we use the code Windows?.Handler?.PlatformView the exception will still occurs. Therefore, we need to ensure that the page's handler is not null before proceeding.
Contributor
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
|
/rebase |
99f3805 to
806e7ab
Compare
PureWeen
approved these changes
Sep 10, 2025
PureWeen
pushed a commit
that referenced
this pull request
Sep 18, 2025
…aded event while navigating on MacCatalyst and iOS (#29410) * Fixed Crash on shell navigation for Mac Catalyst * Test case added * test case name modified * updated the fix * Issue linked * curly brace added * modified the condition. * Modified the fix
PureWeen
pushed a commit
that referenced
this pull request
Sep 18, 2025
…aded event while navigating on MacCatalyst and iOS (#29410) * Fixed Crash on shell navigation for Mac Catalyst * Test case added * test case name modified * updated the fix * Issue linked * curly brace added * modified the condition. * Modified the fix
github-actions bot
pushed a commit
that referenced
this pull request
Sep 18, 2025
…aded event while navigating on MacCatalyst and iOS (#29410) * Fixed Crash on shell navigation for Mac Catalyst * Test case added * test case name modified * updated the fix * Issue linked * curly brace added * modified the condition. * Modified the fix
github-actions bot
pushed a commit
that referenced
this pull request
Sep 23, 2025
…aded event while navigating on MacCatalyst and iOS (#29410) * Fixed Crash on shell navigation for Mac Catalyst * Test case added * test case name modified * updated the fix * Issue linked * curly brace added * modified the condition. * Modified the fix
github-actions bot
pushed a commit
that referenced
this pull request
Sep 23, 2025
…aded event while navigating on MacCatalyst and iOS (#29410) * Fixed Crash on shell navigation for Mac Catalyst * Test case added * test case name modified * updated the fix * Issue linked * curly brace added * modified the condition. * Modified the fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Details:
When navigating away from the current page, the user disconnects all handlers including those of visual elements and the page itself during the Unloaded event of the current page. This leads to crash with a message " System.InvalidOperationException" is thrown when navigating back to the previous page.
Root Cause:
When navigating back to the previous page, the Unloaded event of the current page is triggered. As part of this event, the handler for the page is explicitly disconnected by the user. However, after the handler is cleared and the Unloaded event is attempts to save a token for wiring up the Loaded event via the SendLoaded method.
At this point, since the handler has already been set to null, calling SendLoaded results in a System.InvalidOperationException, as it requires a valid handler. This is why the exception only occurs during backward navigation.
Description of Change:
I have applied condition to call the SendLoaded method only if the handler is not null in iOS and Mac platform.
Tested the behavior in the following platforms.
Reference:
N/A
Issues Fixed:
Fixes #29297
Screenshots
withoutfix.mov
withfix.mov