Unity-Technologies/UnityCsReference · error · ArgumentException
The source path cannot be empty.
Error message
The source path cannot be empty.
What it means
The same shared guard throws ArgumentException with message 'The source path cannot be empty.' when source is the empty string (dest empty yields its own message). Empty-string is treated distinctly from null because a null arg usually means a missing value whereas empty often means a lookup that resolved to nothing.
Source
Thrown at Editor/Mono/FileUtil.bindings.cs:102
"Failed to Copy File / Directory from '{0}' to '{1}': destination path already exists.", source, dest));
}
if (!MoveFileOrDirectoryInternal(source, dest))
{
throw new System.IO.IOException(string.Format(
"Failed to Move File / Directory from '{0}' to '{1}'.", source, dest));
}
}
[FreeFunction("MoveFileOrDirectory")]
private static extern bool MoveFileOrDirectoryInternal(string source, string dest);
private static void CheckForValidSourceAndDestinationArgumentsAndRaiseAnExceptionWhenNullOrEmpty(string source, string dest)
{
if (source == null) throw new ArgumentNullException("source");
if (dest == null) throw new ArgumentNullException("dest");
if (source == string.Empty) throw new ArgumentException("source", "The source path cannot be empty.");
if (dest == string.Empty) throw new ArgumentException("dest", "The destination path cannot be empty.");
}
// Returns a unique path in the Temp folder within your current project.
[FreeFunction]
public static extern string GetUniqueTempPathInProject();
[FreeFunction("GetActualPathSlow")]
internal static extern string GetActualPathName(string path);
//*undocumented*
[FreeFunction]
public static extern string GetProjectRelativePath(string path);
[FreeFunction(Name = "GetLastPathNameComponentManaged")]
internal static extern string GetLastPathNameComponent(string path);
[FreeFunction(Name = "DeleteLastPathNameComponentManaged")]View on GitHub (pinned to 225b0fbdb5)
Solutions
- Check string.IsNullOrWhiteSpace(source) before calling and skip/log when empty.
- When sourcing from GUIDToAssetPath, validate the returned path and report the stale GUID.
- Treat empty and null paths identically at the call boundary.
Example fix
// before
FileUtil.CopyFileOrDirectory(AssetDatabase.GUIDToAssetPath(guid), dst);
// after
string src = AssetDatabase.GUIDToAssetPath(guid);
if (string.IsNullOrWhiteSpace(src)) { Debug.LogError($"GUID {guid} resolves to no path"); return; }
FileUtil.CopyFileOrDirectory(src, dst); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(source))
throw new ArgumentException("source path is empty", nameof(source));
FileUtil.CopyFileOrDirectory(source, dest); Type guard
static bool IsNonEmptyPath(string p) => !string.IsNullOrWhiteSpace(p);
Prevention
- Treat empty and null paths identically at the call boundary (string.IsNullOrWhiteSpace).
- When sourcing paths from GUIDToAssetPath, validate the result and report stale GUIDs.
- Distinguish 'lookup returned empty' from 'value genuinely missing' in diagnostics.
When it happens
Trigger: Passing an empty string as source — e.g. AssetDatabase.GUIDToAssetPath returned "" for a GUID that no longer maps to an asset, or a config field defaulted to string.Empty.
Common situations: Deleted asset whose GUID is still referenced in a script: GUIDToAssetPath returns "" and the copy/move receives an empty source. Missing configuration where a path field is initialised to string.Empty rather than null.
Related errors
- Path cannot be null or empty.
- FileUtil.OpenRead: Invalid UDS hash in path '{path}'
- TierSettings.renderingPath must be actual rendering path (no
- Filters must be declared in pairs { "FileType", "FileExtensi
- Invalid minSize: {value}
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/9f281e14626dea72.
Report an issue: GitHub.