stride3d/stride · error · InvalidOperationException
A session is already open in this instance.
Error message
A session is already open in this instance.
What it means
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.
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
Example fix
// before await editor.NewSession(parameters); // after if (editor.Session == null) await editor.NewSession(parameters);
Defensive patterns
Strategy: validation
Validate before calling
if (editor.Session != null) throw new InvalidOperationException("Close the current session first"); Type guard
bool CanOpenNewSession(EditorViewModel e) => e.Session == null;
Try / catch
try { await editor.NewSession(p); } catch (InvalidOperationException) { /* session already open */ } Prevention
- Check Session == null before NewSession
- Close the session first
- Disable New commands while a session is open
When it happens
Trigger: Calling NewSession (e.g. File > New) while a session is already loaded — Session != null.
Common situations: Automation/scripts invoking new-session commands without closing the current session; UI code not disabling 'New' when a session is open.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Expecting a package that is already registered in this…
- No Collection item identifier associated to the given…
- Package RootDirectory is null
- Cannot add the asset
- Cannot query package with dependencies when it is not…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/55eb3895d9ac6c1f.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Core.Assets.Editor/ViewModel/EditorViewModel.cs:113
#if DEBUG
public ICommandBase DebugCommand { get; }
#endif
// Temporary, until we integrate a proper text editor in the studio
protected internal virtual IEnumerable<string> TextAssetTypes => Enumerable.Empty<string>();
#if DEBUG
public void DebugFunction()
{
Console.WriteLine(@"DebugFunction invoked");
}
#endif
public async Task<bool> NewSession(NewSessionParameters newSessionParameters)
{
if (Session != null)
throw new InvalidOperationException("A session is already open in this instance.");
var newSession = await SessionViewModel.CreateNewSession(this, ServiceProvider, newSessionParameters);
if (newSession != null)
{
Session = newSession;
MRU.AddFile(Session.SolutionPath, EditorVersionMajor);
}
return Session != null;
}
public async Task<bool?> OpenInitialSession(string initialSessionPath)
{
if (string.IsNullOrWhiteSpace(initialSessionPath))
return false;
// The LoadingStartupSession settings is true, which means that the editor crashed while loading the startup project last time.
// Lets give the user a chance to fix the startup session.View on GitHub (pinned to 96fad776d2)