Critical crash when closing Mopups popup containing SfPdfViewer (“MauiContext should have been set on parent”)

Hello Syncfusion Support,

I am experiencing a critical crash when using Syncfusion.Maui.PdfViewer inside a Mopups modal popup in a .NET MAUI application. The crash occurs consistently when the popup is closed. This happens even without any manual cleanup calls, and even if the viewer is detached from the UI. The issue appears to be caused by internal cleanup logic inside SfPdfViewer_HandlerChanged, which runs after MAUI has already started disconnecting the handler.

Below is the full description.


Problem description

When a Mopups popup contains SfPdfViewer, closing the popup results in an exception:

code
InvalidOperationException: MauiContext should have been set on parent.
   at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view)
   at Microsoft.Maui.Handlers.LayoutHandler.Remove(IView child)
   at Syncfusion.Maui.PdfViewer.TextMarkupToolbarView.DisposeItem()
   at Syncfusion.Maui.PdfViewer.SfPdfViewer.DisposeMobileToolbars()
   at Syncfusion.Maui.PdfViewer.SfPdfViewer.CleanupToolbars()
   at Syncfusion.Maui.PdfViewer.SfPdfViewer.SfPdfViewer_HandlerChanged(Object sender, EventArgs e)

This indicates that Syncfusion is attempting to remove child views after the handler has already been disconnected by MAUI during modal teardown.

Steps to reproduce

  1. Create a .NET MAUI project.

  2. Install:

    • Syncfusion.Maui.PdfViewer

    • Mopups

  3. Create a popup page containing:

xml
<ContentView x:Name="PdfContainer">
    <pdfViewer:SfPdfViewer x:Name="PdfViewer" />
</ContentView>
  1. Open the popup.

  2. Close the popup using:

csharp
await PopupNavigation.Instance.PopAsync();
  1. The application crashes.

Expected behavior

The popup should close without exceptions. The PDF Viewer should safely clean up its internal toolbar views even if the handler is being disconnected.

Actual behavior

The app crashes because Syncfusion attempts to remove child views from a parent whose handler has already been disconnected by MAUI.

Technical analysis

  • Mopups removes the popup page from the visual tree and begins handler disconnection.

  • MAUI starts tearing down the handler (DisconnectHandler()).

  • Syncfusion’s SfPdfViewer_HandlerChanged runs after handler disconnection has already started.

  • Inside CleanupToolbars()DisposeMobileToolbars()DisposeItem(), Syncfusion calls:

LayoutHandler.Remove(child)
  • At this moment, the parent view no longer has a valid MauiContext, which causes the exception.

This suggests that cleanup logic is executed at the wrong lifecycle stage. Cleanup should occur in OnDetachedFromHandler and should check for a valid MauiContext before removing child views.

Workaround

The only reliable workaround is to remove the viewer from the visual tree before closing the popup:

PdfContainer.Content = null;
await PopupNavigation.Instance.PopAsync();

Calling CleanupResources() or DisconnectHandler() manually causes the same crash.

Conclusion

This appears to be a lifecycle bug in Syncfusion’s PDF Viewer. The control assumes that the parent view and its handler are still valid during cleanup, which is not guaranteed in MAUI—especially during modal/popup teardown.

Please investigate and provide a fix or updated cleanup logic that is compatible with MAUI modal navigation and Mopups.

Thank you.


1 Reply

BS Bharathi Selvam Syncfusion Team March 9, 2026 02:28 PM UTC

Hi Andreas,

Thank you for reaching out.

We attempted to replicate the issue by creating a sample using Mopups, displaying the PDF Viewer inside a popup, and then closing the popup. We tested this scenario across all platforms. However, we were unable to reproduce the crash you reported when closing the popup. We have attached a sample and video demonstrating the exact steps we followed during our testing.

Could you please review them and let us know if we may have missed any steps in the reproduction process?

To help us investigate this further, kindly provide the following details:

  • Please confirm whether the issue occurs with the sample we provided.
    If not, please share a modified sample that reproduces the issue.
  • The exact steps to reproduce the crash, in case there are any additional conditions or actions involved.
  • Platform information in which the issue occurs (Android, iOS, Windows, or Mac Catalyst).
  • Device details, if the issue is device‑specific.
  • A screen recording or video showing the crash behavior.

We look forward to your response.

Regards,
Bharathi S


Attachment: SampleAndVideo_9c436e7c.zip

Loader.
Up arrow icon