JosefNemec/Playnite · error · ArgumentException

Root directory is not set or does not exist.

Error message

Root directory is not set or does not exist.

What it means

Thrown by the SafeFileEnumerator(DirectoryInfo,...) constructor when root is null or its Exists flag is false. It is an ArgumentException on the 'root' parameter, fired before enumeration begins.

Source

Thrown at source/Playnite/Common/SafeFileEnumerator.cs:192

            : this(new DirectoryInfo(root), pattern, option)
        { }

        /// <summary>
        /// Create an Enumerator that will scan the file system, skipping directories where access is denied
        /// </summary>
        /// <param name="root">Starting Directory</param>
        /// <param name="pattern">Filter pattern</param>
        /// <param name="option">Recursive or not</param>
        public SafeFileEnumerator(DirectoryInfo root, string pattern, SearchOption option)
            : this(root, pattern, option, new List<Exception>())
        { }

        // Internal constructor for recursive itterator
        private SafeFileEnumerator(DirectoryInfo root, string pattern, SearchOption option, IList<Exception> errors)
        {
            if (root == null || !root.Exists)
            {
                throw new ArgumentException("Root directory is not set or does not exist.", "root");
            }
            this.root = root;
            this.searchOption = option;
            this.pattern = String.IsNullOrEmpty(pattern)
                ? "*"
                : pattern;
            this.errors = errors;
        }

        /// <summary>
        /// Errors captured while parsing the file system.
        /// </summary>
        public Exception[] Errors
        {
            get
            {
                return errors.ToArray();
            }

View on GitHub (pinned to 5911f4e964)

Solutions

  1. Check root != null && root.Exists before constructing the enumerator.
  2. Verify the drive/share is mounted and reachable.
  3. Wrap construction in try/catch and treat missing roots as empty results.

Example fix

// before
var files = new SafeFileEnumerator(new DirectoryInfo(root), pattern, SearchOption.AllDirectories);

// after
var di = new DirectoryInfo(root);
if (!di.Exists)
{
    logger.Warn($"Search root missing: {root}");
    return Enumerable.Empty<string>();
}
var files = new SafeFileEnumerator(di, pattern, SearchOption.AllDirectories);
Defensive patterns

Strategy: validation

Validate before calling

if (root == null || !root.Exists) throw new ArgumentException("root missing");

Type guard

static bool IsValidRoot(DirectoryInfo d) => d != null && d.Exists;

Try / catch

try { return new SafeFileEnumerator(root, pattern, option); }
catch (ArgumentException ex) { logger.Warn(ex.Message); return Enumerable.Empty<string>(); }

Prevention

When it happens

Trigger: Constructing the enumerator with a DirectoryInfo whose path does not exist, was deleted, lives on an unmounted drive, or was passed null; a recursive child whose parent was removed mid-traversal.

Common situations: Searching a game library root that was uninstalled/moved; enumerating a removable drive that was ejected; typo in a configured search root; network share offline at scan time.

Related errors


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