{"record":{"id":"e0e8c15db23b50ea","repo":"Unity-Technologies/UnityCsReference","slug":"error-while-reading-window-layout-no-main-window","errorCode":null,"errorMessage":"Error while reading window layout: no main window found","messagePattern":"Error while reading window layout: no main window found","errorType":"exception","errorClass":"LayoutException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/WindowLayout.cs","lineNumber":1446,"sourceCode":"                    // Delete the current mainWindow so that we can load back the previous layout otherwise every attemp at loading a layout will fail.\n                    if (mainWindow.rootView == null || !mainWindow.rootView)\n                    {\n                        mainWindow.Close();\n                        UnityObject.DestroyImmediate(mainWindow, true);\n                        throw new LayoutException(\"Error while reading window layout: no root view on main window.\");\n                    }\n\n                    mainWindow.Show(mainWindow.showMode, loadPosition: true, displayImmediately: true, setFocus: true);\n                    if (mainWindowToSetSize && mainWindow.maximized != mainWindowMaximized)\n                        mainWindow.ToggleMaximize();\n\n                    // Make sure to restore the save to layout flag when loading a layout from a file.\n                    if (flags.HasFlag(LoadWindowLayoutFlags.KeepMainWindow))\n                        mainWindow.m_DontSaveToLayout = false;\n                }\n                else if (!flags.HasFlag(LoadWindowLayoutFlags.NoMainWindowSupport))\n                {\n                    throw new LayoutException(\"Error while reading window layout: no main window found\");\n                }\n\n                // Show other windows\n                for (int i = 0; i < newWindows.Count; i++)\n                {\n                    if (newWindows[i] == null)\n                        continue;\n\n                    EditorWindow win = newWindows[i] as EditorWindow;\n                    if (win)\n                        win.minSize = win.minSize; // Causes minSize to be propagated upwards to parents!\n\n                    ContainerWindow containerWindow = newWindows[i] as ContainerWindow;\n                    if (containerWindow && containerWindow != mainWindow)\n                    {\n                        containerWindow.Show(containerWindow.showMode, loadPosition: false, displayImmediately: true, setFocus: true);\n                        if (flags.HasFlag(LoadWindowLayoutFlags.NoMainWindowSupport))\n                        {","sourceCodeStart":1428,"sourceCodeEnd":1464,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/WindowLayout.cs#L1428-L1464","documentation":"After loading a layout, if no window with ShowMode.MainWindow was found among the deserialized objects, and the caller did not opt out of main-window support via LoadWindowLayoutFlags.NoMainWindowSupport, the editor throws LayoutException. A valid editor session fundamentally requires a main window, so loading a layout without one is a fatal configuration error.","triggerScenarios":"Loading a layout file that contains only floating/secondary windows (no MainWindow); a layout saved in a non-standard mode; passing a flag set that does not include NoMainWindowSupport when intentionally loading an auxiliary-only layout.","commonSituations":"Saving a layout from a build/configuration without a main window; corrupt deserialization dropping the main window entry; misuse of the layout-loading API.","solutions":["Use a layout file that includes a main window, or pass LoadWindowLayoutFlags.NoMainWindowSupport if auxiliary-only loading is intended.","Fall back to the default layout which always defines a main window.","Regenerate the layout by saving from a normal editor session.","Verify the layout was not produced by a stripped/editor-batchmode configuration."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// for auxiliary-only loads, opt out of main-window requirement\nLoadWindowLayout(path, LoadWindowLayoutFlags.NoMainWindowSupport);","typeGuard":null,"tryCatchPattern":"try { LoadWindowLayout(path, flags); }\ncatch (LayoutException ex) when (ex.Message.Contains(\"no main window found\"))\n{ LoadDefaultWindowLayout(); }","preventionTips":["Ensure layout files include a MainWindow entry.","Pass NoMainWindowSupport only when intentionally loading auxiliary windows.","Regenerate layouts from a normal editor session."],"tags":["window-layout","configuration","invalid-state","editor","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}