JosefNemec/Playnite · error · Exception

Interactive session is already running

Error message

Interactive session is already running

What it means

Thrown by PowerShellRuntime.StartInteractiveSession when a previous interactive PowerShell session (interactiveRuntime) is still alive. Playnite supports only one attached interactive PS host at a time because it shares a single runspace ('PSInteractive') with the host process, so a second start is refused.

Source

Thrown at source/Playnite/Scripting/PowerShell/PowerShell.cs:130

            powershell = System.Management.Automation.PowerShell.Create(initialSessionState);
            runspace = powershell.Runspace;
            runspace.Name = runspaceName;
            SetVariable("ErrorActionPreference", "Stop");
            SetVariable("__logger", LogManager.GetLogger(runspaceName));
        }

        public void Dispose()
        {
            IsDisposed = true;
            runspace.Close();
            runspace.Dispose();
        }

        public static void StartInteractiveSession(Dictionary<string, object> variables = null)
        {
            if (interactiveRuntime != null)
            {
                throw new Exception("Interactive session is already running");
            }

            interactiveRuntime = new PowerShellRuntime("PSInteractive");
            variables?.ForEach(a => interactiveRuntime.SetVariable(a.Key, a.Value));
            interactiveProcess = new Process();
            interactiveProcess.StartInfo.FileName = @"c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe";

            // This is really sad solution, but there's currently no way how to initialize these variables automatically, because:
            // - Enter-PSHostProcess is blocking so we can't pass any command after it
            // - We can't redirect stdin because then user wouldn't be able to interact witht the console
            // - Messages like WM_PASTE don't work on PowerShell console
            // - Passing CTLR-V and ENTER is not possible, because the only reliable method works globaly and can't be sent directly to window handle
            interactiveProcess.StartInfo.Arguments = $"-NoExit -Command \"" +
                $"Write-Host \"`n" +
                $"`tConnected to Playnite process.`n" +
                $"`tUse CTLR-V and ENTER to paste commands to initialize basic SDK variables.`n" +
                $"`tMore information at:`n" +
                $"`thttps://playnite.link/docs/master/tutorials/extensions/scriptingDebugging.html`n" +

View on GitHub (pinned to 5911f4e964)

Solutions

  1. Close the existing interactive PowerShell window (type 'exit' or close it) so the Exited handler disposes interactiveRuntime.
  2. If the field is stuck non-null after a crash, restart Playnite to reset static state.
  3. Before calling StartInteractiveSession again, confirm interactiveRuntime is null / IsDisposed.
  4. Avoid issuing multiple Open Interactive Session commands in rapid succession.

Example fix

// before
PowerShellRuntime.StartInteractiveSession(vars);
PowerShellRuntime.StartInteractiveSession(vars); // throws

// after
PowerShellRuntime.StartInteractiveSession(vars);
// ... user works, closes the window, Exited handler nulls interactiveRuntime ...
PowerShellRuntime.StartInteractiveSession(vars); // ok
Defensive patterns

Strategy: validation

Validate before calling

// No public getter is exposed; track liveness at the call site before starting:
// (reflective/field check is internal — callers should keep a single owner of StartInteractiveSession)
if (interactiveSessionStarted) { /* inform user a session is already running */ return; }
PowerShellRuntime.StartInteractiveSession(vars);
interactiveSessionStarted = true;

Type guard

// Not externally type-guardable; guard at the command/UI layer:
bool CanStartInteractiveSession() => !interactiveSessionStarted;

Try / catch

try { PowerShellRuntime.StartInteractiveSession(vars); }
catch (Exception ex) when (ex.Message.Contains("already running")) { /* tell user to close the existing window */ }

Prevention

When it happens

Trigger: StartInteractiveSession is invoked while interactiveRuntime != null (line 128). The previous process may still be running because its Exited handler only nulls interactiveRuntime after the powershell.exe process exits.

Common situations: User opened the interactive PowerShell debug session, then triggered Open Interactive Session again without closing the first. The previous powershell.exe window was closed via the X button but the process hadn't fully terminated and fired Exited yet. A crashed earlier session left interactiveRuntime non-null.

Related errors


AI-assisted analysis of JosefNemec/Playnite@5911f4e964 (2026-08-13). Data as JSON: /api/errors/8bad338ceca06798. Report an issue: GitHub.