Skip to content

[iOS] "Window was already destroyed" on every force-close when MainPage is used with UIScene lifecycle (now mandatory with iOS 27 SDK) #40438

Open

Description

@Stensan

Description

Follow-up to #24191, which was closed as not planned and is now locked. Since then the situation has changed. Apps built with the iOS 27 SDK (Xcode 27) that have not adopted the UIScene lifecycle are terminated by UIKit at launch on iOS 27 (_UIApplicationEvaluateRuntimeIssueForNoSceneLifecycleAdoption, EXC_BREAKPOINT). Every MAUI iOS app therefore has to add a UIApplicationSceneManifest (__MAUI_DEFAULT_SCENE_CONFIGURATION__ + MauiUISceneDelegate).

As soon as it does, every app that still sets Application.MainPage throws InvalidOperationException: Window was already destroyed on every force-close from the app switcher, on all iOS versions. MainPage is obsolete but still supported, and large existing apps cannot always migrate to CreateWindow immediately.

Root cause (verified by decompiling 10.0.120, unchanged in 10.0.130 and 11.0.10):

  1. SceneDidDisconnect → windowScene.GetWindow()?.Destroying() → IsDestroyed = true
  2. Window.IWindow.Destroying() → Application.RemoveWindow(this) does not remove the window when window.Page == _singleWindowMainPage, so it stays in Application.Windows
  3. WillTerminate → app.GetWindow()?.Destroying() → GetWindow() returns Windows[0] → second call → throws

Unlike WillEnterForeground, OnActivated, OnResignActivation and DidEnterBackground, the WillTerminate handler in AppHostBuilderExtensions.iOS.cs has no guard.

Suggested fix:

.WillTerminate(app =>
{
    // With a scene manifest the window was already destroyed in SceneDidDisconnect
    if (app.GetWindow() is { Handler: not null } window)
        window.Destroying();
    KeyboardAutoManagerScroll.Disconnect();
})

Steps to Reproduce

  1. Create a MAUI app that sets MainPage in the App constructor (no CreateWindow override)
  2. Add UIApplicationSceneManifest to Info.plist with __MAUI_DEFAULT_SCENE_CONFIGURATION__ and UISceneDelegateClassName = SceneDelegate
  3. Add [Register("SceneDelegate")] public class SceneDelegate : MauiUISceneDelegate { }
  4. Run the app (without debugger), open the app switcher and swipe the app away
  5. InvalidOperationException: Window was already destroyed is thrown from MauiUIApplicationDelegate.WillTerminate

Link to public reproduction project repository

The reproduction from #24191 still applies: https://github.com/BenDTU/MauiUISceneConfigurationCrash

Version with bug

10.0.130

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.101 (according to #24191)

Affected platforms

iOS

Affected platform versions

iOS 18.7 (device). With the iOS 27 SDK it affects all versions, because the scene manifest becomes mandatory.

Did you find any workaround?

Override WillTerminate in the AppDelegate. A destroyed window has its handler disconnected:

public override void WillTerminate(UIApplication application)
{
    if (application.GetWindow() is { Handler: null })
        return;

    base.WillTerminate(application);
}

Alternatively migrate from MainPage to CreateWindow.

Relevant log output

System.InvalidOperationException: Window was already destroyed
   at Microsoft.Maui.Controls.Window.Microsoft.Maui.IWindow.Destroying()
   at Microsoft.Maui.LifecycleEvents.AppHostBuilderExtensions.<>c.<OnConfigureLifeCycle>b__2_1(UIApplication app)
   at Microsoft.Maui.MauiUIApplicationDelegate.<>c__DisplayClass16_0.<WillTerminate>b__0(WillTerminate del)
   at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[WillTerminate](IServiceProvider services, Action`1 action)
   at Microsoft.Maui.MauiUIApplicationDelegate.WillTerminate(UIApplication application)

Activity

  1. NafeelaNazhir commented on Nov 20, 2026

    @NafeelaNazhir
    Contributor

    This issue has been validated in Visual Studio Code 1.147.0 with .NET MAUI versions 10.0.130 and 11.0.10. It can be reproduced on the iOS platform.

    MauiUISceneConfigurationCrash-main 2.zip

    Screen.Recording.2026-11-20.at.11.30.46.AM.mov
  2. added a commit that references this issue on Nov 20, 2026
    d5925a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions