maui icon indicating copy to clipboard operation
maui copied to clipboard

Fix for exception thrown when disconnecting page handlers in the Unloaded event while navigating on MacCatalyst and iOS

Open KarthikRajaKalaimani opened this issue 6 months ago • 8 comments
trafficstars

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">

KarthikRajaKalaimani avatar May 09 '25 06:05 KarthikRajaKalaimani

/azp run MAUI-UITests-public

jsuarezruiz avatar May 09 '25 06:05 jsuarezruiz

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar May 09 '25 06:05 azure-pipelines[bot]

/azp run

rmarinho avatar May 13 '25 09:05 rmarinho

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar May 13 '25 09:05 azure-pipelines[bot]

/azp run MAUI-UITests-public

jsuarezruiz avatar Jun 09 '25 06:06 jsuarezruiz

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 09 '25 06:06 azure-pipelines[bot]

/azp run MAUI-UITests-public

jsuarezruiz avatar Jun 17 '25 08:06 jsuarezruiz

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 17 '25 08:06 azure-pipelines[bot]

/rebase

PureWeen avatar Jul 20 '25 01:07 PureWeen