Repository navigation
Description
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):
SceneDidDisconnect→windowScene.GetWindow()?.Destroying()→IsDestroyed = trueWindow.IWindow.Destroying()→Application.RemoveWindow(this)does not remove the window whenwindow.Page == _singleWindowMainPage, so it stays inApplication.WindowsWillTerminate→app.GetWindow()?.Destroying()→GetWindow()returnsWindows[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
- Create a MAUI app that sets
MainPagein theAppconstructor (noCreateWindowoverride) - Add
UIApplicationSceneManifestto Info.plist with__MAUI_DEFAULT_SCENE_CONFIGURATION__andUISceneDelegateClassName=SceneDelegate - Add
[Register("SceneDelegate")] public class SceneDelegate : MauiUISceneDelegate { } - Run the app (without debugger), open the app switcher and swipe the app away
InvalidOperationException: Window was already destroyedis thrown fromMauiUIApplicationDelegate.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
NafeelaNazhir commentedon Nov 20, 2026
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
[iOS] Don't destroy an already destroyed window in WillTerminate (#40452