Skip to content

[BUG] Conflict between popups and AppShell Title #2887

@brendanrempel

Description

@brendanrempel

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

This appears to be a conflict between the latest Popup functionality and AppShell/TitleBar. While the two operate correctly, they are causing a conflict that causes the application to crash when exiting. No stack dump is available and can be reproduced on a hello world app. Specifically, the unhandled exception occurs:

Exception: Value does not fall within the expected range.
Message: Invalid window; it belongs to other thread.

Expected Behavior

Exiting the application should not have an error.

Steps To Reproduce

  1. Create a MAUI project on Windows, DotNet9. Target the build/debug for localhost.
  2. I believe this is optional, but in NUGET, perform all updates (should only be a couple)
  3. Add Community Toolkit needed for Popups
  4. Create a new view, change the parent to Popup.
  5. I changed the popup constructor to accept an action, call the action on button click
  6. In MainPage.xaml.cs, add this code to bring up the popup:

`protected override async void OnAppearing()
{
if (!firstLoad) return;

firstLoad = false;

CancellationToken token = new();

var popup = new PageTest(async () =>
{
await this.ClosePopupAsync(token);
});

await this.ShowPopupAsync(
//await Shell.Current.ShowPopupAsync(
popup,
new PopupOptions(),
token);
}`

  1. Run the app, close the popup, then close the app. It should close correctly.
  2. Change this method in the App.xaml.cs:

protected override Window CreateWindow(IActivationState? activationState) { return new Window(new AppShell()) { // BUG - this option causes popups to crash TitleBar = new TitleBar() { Title = "title", Subtitle = "subject" } }; }

  1. Repeat running the app. Close the popup, close the app.
  2. An unhandled exception should occur.
  3. Alternatively, comment out the popup also fixes the crash.

Link to public reproduction project repository

https://github.com/brendanrempel/popupcrash/tree/main/MauiPopup

Environment

- .NET MAUI CommunityToolkit: 12.2.0
- OS: Windows 24H2 26120.5770
- .NET MAUI: DotNet 9
- Version 17.14.14

Anything else?

Duplicate of 2877 which was closed without resolving.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions