CoplayDev/unity-mcp · error · InvalidOperationException
Install Dir resolved to an empty path.
Error message
Install Dir resolved to an empty path.
What it means
After ExpandPath returns, if the result is null/empty/whitespace the sync cannot proceed. This guards the rare case where expansion (e.g. '~' resolved via Environment.GetFolderPath) yields an empty string.
Source
Thrown at MCPForUnity/Editor/Setup/SkillSyncService.cs:688
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();
if (expanded.StartsWith("~", StringComparison.Ordinal))
{
var userHome = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
expanded = Path.Combine(userHome, expanded.Substring(1).TrimStart('/', '\\'));
}View on GitHub (pinned to c21bf496bc)
Solutions
- Provide an absolute path instead of relying on '~' expansion.
- Ensure the process has a valid user profile/home directory.
- Set an explicit install directory in Advanced Settings.
Defensive patterns
Strategy: validation
Validate before calling
var expanded = SkillSyncService.ExpandPath(installDir);
if (string.IsNullOrWhiteSpace(expanded))
{
throw new ArgumentException("Install dir resolved to empty. Provide an absolute path.");
} Prevention
- Prefer absolute paths over '~' in headless/container environments.
- Ensure the process runs with a valid user profile/home directory.
- Set an explicit install directory in Advanced Settings.
When it happens
Trigger: A tilde path on a headless/container environment where Environment.GetFolderPath(UserProfile) returns empty; an edge case in Path.GetFullPath producing whitespace.
Common situations: Running inside a minimal container or service account with no user profile; CI agent without a home directory.
Related errors
- Install Dir is empty.
- Install Dir contains invalid path characters: {installDir}
- Install Dir is invalid and cannot be resolved: {installDir}
- Failed to write config file '{path}': {ex.Message}
- Source path cannot be empty.
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/430f0725d3e7fb48.
Report an issue: GitHub.