Skip to content

Closing a child window causes a crash in a WinUI3 XAML-hosted application. #10495

@Ajith-GS

Description

@Ajith-GS

Describe the bug

In a WinUI 3 XAML-hosted application, when closing an explicitly created child window, it throws exception and causes application crash.
We are creating and activating a WinUI 3 window using a button click handler available in the XAML page, which is hosted over the native application.
In this scenario, should we do any extra handling to close the newly created window properly?
Any help is appreciated.

Steps to reproduce the bug

  1. Download and build the XAML Island sample application available in the following repo.
    https://github.com/microsoft/WindowsAppSDK-Samples/tree/main/Samples/Islands
  2. Add the following lines of code inside the WinUI button click handler available in the "MainPage" cpp file.
auto ChildWindow = Microsoft::UI::Xaml::Window();
ChildWindow.Activate();
  1. Build and run the application.
  2. Click the WinUI 3 button.
  3. Close the newly created WinUI 3 window using close icon.

Expected behavior

The window should close without any exception, and the parent app should continue to run as it is.

Screenshots

No response

NuGet package version

Windows App SDK 1.4.3: 1.4.231115000

Packaging type

Unpackaged

Windows version

Windows 10 version 22H2 (19045, 2022 Update)

IDE

Visual Studio 2022

Additional context

The same behavior is found if we create an XAML window using the Blank Window (WinUI 3 in Desktop) template and activate it inside the button click handler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-WindowingbugSomething isn't workingneeds-triageIssue needs to be triaged by the area owners

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions