{"record":{"id":"55eb3895d9ac6c1f","repo":"stride3d/stride","slug":"a-session-is-already-open-in-this-instance","errorCode":null,"errorMessage":"A session is already open in this instance.","messagePattern":"A session is already open in this instance\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/ViewModel/EditorViewModel.cs","lineNumber":113,"sourceCode":"\n#if DEBUG\n        public ICommandBase DebugCommand { get; }\n#endif\n\n        // Temporary, until we integrate a proper text editor in the studio\n        protected internal virtual IEnumerable<string> TextAssetTypes => Enumerable.Empty<string>();\n\n#if DEBUG\n        public void DebugFunction()\n        {\n            Console.WriteLine(@\"DebugFunction invoked\");\n        }\n#endif\n\n        public async Task<bool> NewSession(NewSessionParameters newSessionParameters)\n        {\n            if (Session != null)\n                throw new InvalidOperationException(\"A session is already open in this instance.\");\n\n            var newSession = await SessionViewModel.CreateNewSession(this, ServiceProvider, newSessionParameters);\n            if (newSession != null)\n            {\n                Session = newSession;\n                MRU.AddFile(Session.SolutionPath, EditorVersionMajor);\n            }\n\n            return Session != null;\n        }\n\n        public async Task<bool?> OpenInitialSession(string initialSessionPath)\n        {\n            if (string.IsNullOrWhiteSpace(initialSessionPath))\n                return false;\n\n            // The LoadingStartupSession settings is true, which means that the editor crashed while loading the startup project last time.\n            // Lets give the user a chance to fix the startup session.","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/ViewModel/EditorViewModel.cs#L95-L131","documentation":"EditorViewModel.NewSession creates a new SessionViewModel, but only one session may be open per editor instance. If the Session property is already non-null, it throws InvalidOperationException before creating the new session.","triggerScenarios":"Calling NewSession (e.g. File > New) while a session is already loaded — Session != null.","commonSituations":"Automation/scripts invoking new-session commands without closing the current session; UI code not disabling 'New' when a session is open.","solutions":["Close the current session (set Session to null via CloseSession) before calling NewSession","Check EditorViewModel.Session for null before invoking NewSession","Disable New-session UI commands while a session is open"],"exampleFix":"// before\nawait editor.NewSession(parameters);\n// after\nif (editor.Session == null) await editor.NewSession(parameters);","handlingStrategy":"validation","validationCode":"if (editor.Session != null) throw new InvalidOperationException(\"Close the current session first\");","typeGuard":"bool CanOpenNewSession(EditorViewModel e) => e.Session == null;","tryCatchPattern":"try { await editor.NewSession(p); } catch (InvalidOperationException) { /* session already open */ }","preventionTips":["Check Session == null before NewSession","Close the session first","Disable New commands while a session is open"],"tags":["session","viewmodel","state"],"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-15T23:17:13.987Z"}