CoplayDev/unity-mcp · error · InvalidOperationException

Install Dir is invalid and cannot be resolved: {installDir}

Error message

Install Dir is invalid and cannot be resolved: {installDir}

What it means

ExpandPath performs tilde expansion then Path.GetFullPath; if that throws (path too long, security exception, unreachable root, malformed), ResolveAndValidateInstallPath wraps it in this message with the original exception as inner.

Source

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

            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);
            }

            if (string.IsNullOrWhiteSpace(expandedPath))
            {
                throw new InvalidOperationException("Install Dir resolved to an empty path.");
            }

            return expandedPath;
        }

        internal static string ExpandPath(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return string.Empty;
            }

            var expanded = path.Trim();

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Use a shorter absolute path.
  2. Check folder and parent-directory permissions.
  3. Avoid deeply nested or unusually structured paths.
  4. Inspect the inner exception in the log for the specific GetFullPath failure.
Defensive patterns

Strategy: validation

Validate before calling

try { _ = Path.GetFullPath(installDir.Trim()); }
catch (Exception ex) { throw new ArgumentException("Install dir cannot be resolved.", ex); }

Prevention

When it happens

Trigger: Path exceeds system length limits at GetFullPath; a SecurityException denies path resolution; the expanded path references a drive/root that cannot be resolved on the current platform.

Common situations: Very deep nested path on Windows; running under restricted permissions; mixing POSIX separators on a system that rejects them.

Related errors


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