{"record":{"id":"eba8e81f5564b1a1","repo":"stride3d/stride","slug":"this-application-already-has-a-main-window","errorCode":null,"errorMessage":"This application already has a main window.","messagePattern":"This application already has a main window\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Windows/WindowManager.cs","lineNumber":104,"sourceCode":"\n            Logger.Info($\"{nameof(WindowManager)} disposed\");\n            initialized = false;\n        }\n\n        /// <summary>\n        /// Shows the given window as the main window of the application. It is mandatory to use this method for the main window to use features of the <see cref=\"WindowManager\"/>.\n        /// </summary>\n        /// <param name=\"window\">The main window to show.</param>\n        public static void ShowMainWindow([NotNull] Window window)\n        {\n            if (window == null) throw new ArgumentNullException(nameof(window));\n            CheckDispatcher();\n\n            if (MainWindow != null)\n            {\n                var message = \"This application already has a main window.\";\n                Logger.Error(message);\n                throw new InvalidOperationException(message);\n            }\n            Logger.Info($\"Main window showing. ({window})\");\n\n            MainWindow = new WindowInfo(window);\n            AllWindowsList.Add(MainWindow);\n\n            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;\n            window.Show();\n        }\n\n        /// <summary>\n        /// Shows the given window as blocking window. A blocking window will always block the main window of the application, even if shown before it, but does not\n        /// affect modal windows. However it can still be blocked by them..\n        /// </summary>\n        /// <param name=\"window\">The blocking window to show.</param>\n        public static void ShowBlockingWindow([NotNull] Window window)\n        {\n            if (window == null) throw new ArgumentNullException(nameof(window));","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Windows/WindowManager.cs#L86-L122","documentation":"WindowManager allows only one main window per application. ShowMainWindow throws InvalidOperationException when MainWindow is already set, because assigning a second main window would break owner/window-management bookkeeping. The error is logged before throwing.","triggerScenarios":"Calling ShowMainWindow twice in one application lifetime, e.g. re-invoking it on a second startup path or after re-creating a window without closing/unregistering the first.","commonSituations":"App restart logic that shows a new shell window; plugin or module code that independently tries to register its window as main; unit tests that call ShowMainWindow without resetting WindowManager state between tests.","solutions":["Only call ShowMainWindow once, at application startup","Check WindowManager.MainWindow != null before calling ShowMainWindow and reuse/activate the existing window instead","Close and reset the existing main window (via WindowManager APIs) before showing a new one","Guard the call with a once-only initialization flag in your app bootstrap"],"exampleFix":"// before\nwindowManager.ShowMainWindow(mainWindow);\n// later\nwindowManager.ShowMainWindow(newMainWindow); // throws\n// after\nif (windowManager.MainWindow == null)\n    windowManager.ShowMainWindow(newMainWindow);\nelse\n    windowManager.MainWindow.Window.Activate();","handlingStrategy":"validation","validationCode":"if (windowManager.MainWindow == null) windowManager.ShowMainWindow(window); else windowManager.MainWindow.Window.Activate();","typeGuard":null,"tryCatchPattern":"try { windowManager.ShowMainWindow(window); } catch (InvalidOperationException) { /* main window already exists; activate it instead */ }","preventionTips":["Show the main window exactly once in app bootstrap","Route all window creation through a single entry point","Assert MainWindow == null in debug builds before showing"],"tags":["wpf","window-management","invalid-operation"],"backgroundTag":"invalid-state-transition","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}