stride3d/stride · error · ArgumentException

path [ ] doesn't contain a /

Error message

path [{path}] doesn't contain a /

What it means

VirtualFileSystem.GetParentFolder returns the parent portion of a virtual path by locating the last directory separator. If the path contains no '/' at all, LastIndexOfDirectorySeparator returns -1 and this ArgumentException is thrown, since there is no parent folder to compute.

Solutions

  1. Ensure the argument is a virtual path containing at least one '/' before calling.
  2. Normalize backslashes to forward slashes (path.Replace('\\', '/')) first.
  3. Guard: only call GetParentFolder when path.Contains('/'), otherwise return "" or the root yourself.
  4. If the file may be at the root, treat the no-slash case as root parent rather than calling the method.

Example fix

// before
var parent = VirtualFileSystem.GetParentFolder(fileName); // throws if no '/'
// after
var parent = fileName.Contains('/') ? VirtualFileSystem.GetParentFolder(fileName) : "";
Defensive patterns

Strategy: validation

Validate before calling

if (path == null || !path.Contains('/'))
    throw new ArgumentException("Virtual path must contain '/'.", nameof(path));

Try / catch

try { parent = VirtualFileSystem.GetParentFolder(path); }
catch (ArgumentException) { parent = ""; /* no folder component */ }

Prevention

When it happens

Trigger: Calling VirtualFileSystem.GetParentFolder with a bare name like "file.txt" or a path using backslashes ("a\b\c.txt") instead of forward slashes, which the virtual file system requires.

Common situations: Passing Windows-style local paths into the virtual FS API; concatenating file names without a directory prefix; reading user-supplied paths that may lack a folder component.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/1e27638b9af3079e. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.IO/VirtualFileSystem.cs:440

            return path1 + DirectorySeparatorChar + path2;

        return path1 + path2;
    }

    /// <summary>
    /// Gets the parent folder.
    /// </summary>
    /// <param name="path">The path.</param>
    /// <returns>The parent folder.</returns>
    /// <exception cref="System.ArgumentNullException">path</exception>
    /// <exception cref="System.ArgumentException">path doesn't contain a /;path</exception>
    public static string GetParentFolder(string path)
    {
        ArgumentNullException.ThrowIfNull(path);

        var lastSlashIndex = LastIndexOfDirectorySeparator(path);
        if (lastSlashIndex == -1)
            throw new ArgumentException($"path [{path}] doesn't contain a /", nameof(path));

        return path[..lastSlashIndex];
    }

    /// <summary>
    /// Gets the file's name with its extension ("/path/to/file/fileName.ext"->"fileName.ext")
    /// </summary>
    /// <param name="path">path containing file's path and name </param>
    /// <returns>The name of the file with its extension</returns>
    public static string GetFileName(string path)
    {
        ArgumentNullException.ThrowIfNull(path);

        var lastSlashIndex = LastIndexOfDirectorySeparator(path);

        return path[(lastSlashIndex + 1)..];
    }

View on GitHub (pinned to 96fad776d2)