maui
maui copied to clipboard
Fix for exception thrown when disconnecting page handlers in the Unloaded event while navigating on MacCatalyst and iOS
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.
- [x] Android
- [x] Windows
- [x] iOS
- [x] Mac
Reference:
N/A
Issues Fixed:
Fixes #29297
Screenshots
| Before | After |
|---|---|
| <Video src="https://github.com/user-attachments/assets/1c647508-17da-49cc-a7bc-0f2491198f31"> | <Video src="https://github.com/user-attachments/assets/862ee821-7f57-49cc-81dc-e2cef4373d11"> |
/azp run MAUI-UITests-public
Azure Pipelines successfully started running 1 pipeline(s).
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
/azp run MAUI-UITests-public
Azure Pipelines successfully started running 1 pipeline(s).
/azp run MAUI-UITests-public
Azure Pipelines successfully started running 1 pipeline(s).
/rebase