CoplayDev/unity-mcp · error · InvalidOperationException

Install Dir is empty.

Error message

Install Dir is empty.

What it means

ResolveAndValidateInstallPath throws when installDir is null or whitespace. The sync needs a concrete target directory before it can create, validate, or write anything.

Source

Thrown at MCPForUnity/Editor/Setup/SkillSyncService.cs:667

            var directories = Directory.GetDirectories(root, "*", SearchOption.AllDirectories);
            Array.Sort(directories, (a, b) => string.CompareOrdinal(b, a));
            foreach (var directory in directories)
            {
                if (Directory.EnumerateFileSystemEntries(directory).Any())
                {
                    continue;
                }

                Directory.Delete(directory, false);
            }
        }

        internal static string ResolveAndValidateInstallPath(string installDir)
        {
            if (string.IsNullOrWhiteSpace(installDir))
            {
                throw new InvalidOperationException("Install Dir is empty.");
            }

            var trimmed = installDir.Trim();
            if (trimmed.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
            {
                throw new InvalidOperationException($"Install Dir contains invalid path characters: {installDir}");
            }

            string expandedPath;
            try
            {
                expandedPath = ExpandPath(trimmed);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"Install Dir is invalid and cannot be resolved: {installDir}", ex);
            }

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Provide a non-empty install directory path.
  2. Set a default in Advanced Settings so the field is never blank.
  3. If calling programmatically, guard against null before invoking SyncAsync.
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(installDir))
{
    throw new ArgumentException("Install directory must not be empty.");
}

Prevention

When it happens

Trigger: The install-directory UI field was left blank; a serialized/EditorPrefs setting resolved to empty; a programmatic caller passed null.

Common situations: First-run with no default set; setting cleared by a reset; caller forgot to pass the path.

Related errors


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