CoplayDev/unity-mcp · error · DirectoryNotFoundException

Source directory not found

Error message

Source directory not found: {dir.FullName}

What it means

Thrown by FileUtility.CopyDirectory when the sourceDir passed to it does not exist on disk (DirectoryInfo.Exists is false). It is a guard before any file enumeration or copying begins, so no partial copy occurs. The exception message echoes dir.FullName for diagnosis.

Solutions

  1. Check Directory.Exists(sourceDir) before calling CopyDirectory and log the absolute path.
  2. Ensure the directory-producing step runs (and succeeds) before the copy step.
  3. Use Path.GetFullPath to resolve relative paths and verify against the expected location.
  4. On network/removable drives, confirm the mount is present before copying.

Example fix

// before
FileUtility.CopyDirectory(stagingDir, destDir, recursive: true);
// after
if (!Directory.Exists(stagingDir)) throw new DirectoryNotFoundException(stagingDir);
FileUtility.CopyDirectory(stagingDir, destDir, recursive: true);
Defensive patterns

Strategy: validation

Validate before calling

if (!Directory.Exists(sourceDir))
    throw new DirectoryNotFoundException(sourceDir);

Type guard

static bool IsCopyableSource(string s) =>
    !string.IsNullOrWhiteSpace(s) && Directory.Exists(s);

Try / catch

try { FileUtility.CopyDirectory(src, dst, recursive: true); }
catch (DirectoryNotFoundException ex) { Debug.LogError(ex.Message); }

Prevention

When it happens

Trigger: Calling CopyDirectory with a non-existent source path, a relative path resolved against the wrong working directory, or a path on a network mount that is unavailable. Also when a path contains typos, wrong drive letters, or trailing separators that change resolution.

Common situations: The build/upload pipeline computes a staging directory that was never created, a previous step cleaned temp dirs, or the path was hardcoded for a different machine. Common in CI where artifacts live in a different location than locally.

Related errors


AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13). Data as JSON: /api/errors/7455ce5c15d88ca4. Report an issue: GitHub.

Appendix: source

Thrown at TestProjects/AssetStoreUploads/Packages/com.unity.asset-store-tools/Editor/Utility/FileUtility.cs:57

                convertedPath = convertedPath.Substring(Constants.RootProjectPath.Length);
            }
            else
            {
                if (allowSymlinks && SymlinkUtil.FindSymlinkFolderRelative(convertedPath, out var symlinkPath))
                    convertedPath = symlinkPath;
            }

            return convertedPath;
        }

        public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive)
        {
            // Get information about the source directory
            var dir = new DirectoryInfo(sourceDir);

            // Check if the source directory exists
            if (!dir.Exists)
                throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}");

            // Cache directories before we start copying
            DirectoryInfo[] dirs = dir.GetDirectories();

            // Create the destination directory
            Directory.CreateDirectory(destinationDir);

            // Get the files in the source directory and copy to the destination directory
            foreach (FileInfo file in dir.GetFiles())
            {
                string targetFilePath = Path.Combine(destinationDir, file.Name);
                file.CopyTo(targetFilePath);
            }

            // If recursive and copying subdirectories, recursively call this method
            if (recursive)
            {
                foreach (DirectoryInfo subDir in dirs)

View on GitHub (pinned to c21bf496bc)