SubtitleEdit/subtitleedit · error · InvalidOperationException

Failed to open file: {filePath}

Error message

Failed to open file: {filePath}

What it means

Thrown by OpenFileWithDefaultProgram as a catch-all wrapper for any exception escaping the Process.Start calls that is not already FileNotFoundException or ArgumentException (those are explicitly filtered out by the when clause). The inner exception is preserved as InnerException. Typical inner causes: Win32Exception (ERROR_NO_ASSOCIATION / file not executable / access denied), the opener binary missing (xdg-open not installed), or permission errors.

Source

Thrown at src/ui/Logic/Media/FileHelper.cs:769

                }
                else if (OperatingSystem.IsLinux())
                {
                    // Linux: use 'xdg-open' command
                    Process.Start(new ProcessStartInfo
                    {
                        FileName = "xdg-open",
                        Arguments = $"\"{filePath}\"",
                        UseShellExecute = false
                    });
                }
                else
                {
                    throw new PlatformNotSupportedException("Unsupported operating system");
                }
            }
            catch (Exception ex) when (ex is not FileNotFoundException && ex is not ArgumentException)
            {
                throw new InvalidOperationException($"Failed to open file: {filePath}", ex);
            }
        }
    }
}

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Inspect InnerException (often a Win32Exception) for the native error code and message.
  2. Register a default application for the file extension (Windows) or install xdg-open / open (Linux/macOS).
  3. Ensure the file and the opener are executable and that the process has launch permissions.
  4. Catch InvalidOperationException around the call and present InnerException.Message to the user with a 'choose app manually' option.

Example fix

// before
FileHelper.OpenFileWithDefaultProgram(path);

// after
catch (InvalidOperationException ex) when (ex.InnerException is System.ComponentModel.Win32Exception we)
{
    if (we.NativeErrorCode == 1155 /*ERROR_NO_ASSOCIATION*/)
        showOpenWithDialog(path); // let user pick an app
    else
        showUser(ex.InnerException.Message);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!OperatingSystem.IsLinux() || File.Exists("/usr/bin/xdg-open"))
    FileHelper.OpenFileWithDefaultProgram(path);
else showUser("xdg-open is not installed");

Try / catch

try { FileHelper.OpenFileWithDefaultProgram(path); }
catch (InvalidOperationException ex) when (ex.InnerException is System.ComponentModel.Win32Exception we)
{
    if (we.NativeErrorCode == 1155 /*ERROR_NO_ASSOCIATION*/) ShowOpenWithDialog(path);
    else showUser(we.Message);
}

Prevention

When it happens

Trigger: Process.Start throws inside the try: no application associated with the file extension on Windows, xdg-open/open missing on Linux/macOS, the file or opener is not executable, or a sandbox blocks the launch.

Common situations: A file type with no registered default app; a minimal Linux distro without xdg-open; macOS Gatekeeper blocking the opener; insufficient permissions to launch.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/c0228c009b937173. Report an issue: GitHub.