Unity-Technologies/UnityCsReference · error · ArgumentNullException
Cannot add source dependency on empty GUID.
Error message
Cannot add source dependency on empty GUID.
What it means
AssetImportContext.DependsOnSourceAsset(GUID guid) is the GUID-based overload of the source dependency API. It throws ArgumentNullException with message 'Cannot add source dependency on empty GUID.' when guid.Empty() returns true, because an empty GUID (all zeros) cannot identify any asset and would register a dependency on nothing. This differs from the string overload (error 25) which validates the path string.
Source
Thrown at Editor/Mono/AssetPipeline/AssetImportContext.bindings.cs:78
// * if the asset at the path moves, it will trigger an import
public void DependsOnSourceAsset(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path", "Cannot add dependency on invalid path.");
}
DependsOnSourceAssetInternal(path);
}
[NativeName("DependsOnSourceAsset")]
private extern void DependsOnSourceAssetInternal(string path);
public void DependsOnSourceAsset(GUID guid)
{
if (guid.Empty())
{
throw new ArgumentNullException("guid", "Cannot add source dependency on empty GUID.");
}
DependsOnSourceAssetInternalGUID(guid);
}
[NativeName("DependsOnSourceAsset")]
private extern void DependsOnSourceAssetInternalGUID(GUID guid);
[NativeName("GetFolderEntries")]
internal extern GUID[] GetFolderEntries(GUID folder);
internal void DependsOnImportedAsset(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path", "Cannot add dependency on invalid path.");
}
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Check guid.Empty() before calling: if (!guid.Empty()) context.DependsOnSourceAsset(guid).
- Validate GUIDs via GUID.TryParse and only proceed if parsing succeeds.
- Treat empty GUIDs as optional dependencies — log and skip rather than throw.
Example fix
// before
context.DependsOnSourceAsset(referencedGuid);
// after
if (!referencedGuid.Empty())
context.DependsOnSourceAsset(referencedGuid);
else
Debug.LogWarning($"{context.assetPath}: source dependency GUID is empty, skipping"); Defensive patterns
Strategy: validation
Validate before calling
if (!guid.Empty())
context.DependsOnSourceAsset(guid);
else
Debug.LogWarning($"{context.assetPath}: empty source dependency GUID"); Type guard
static bool IsValidGuid(GUID guid) => !guid.Empty();
Try / catch
try { context.DependsOnSourceAsset(guid); }
catch (ArgumentNullException ex) when (ex.ParamName == "guid")
{ Debug.LogWarning($"Skipped source dependency: {ex.Message}"); } Prevention
- Check guid.Empty() before all GUID-based dependency calls
- Validate GUIDs with GUID.TryParse at parse time
- Treat empty GUIDs as optional references and skip with a warning
When it happens
Trigger: Calling context.DependsOnSourceAsset(guid) where guid was never assigned (default GUID is empty), or where GUID.TryParse failed but the result was used anyway. Common in importers that read GUIDs from serialized data (e.g., from .meta files or cross-asset references in custom formats).
Common situations: ScriptedImporters parsing external file formats (FBX, custom data) that reference other assets by GUID, where the GUID field is optional or corrupted. Also occurs during migration when GUIDs change and stale references resolve to empty.
Related errors
- Cannot add artifact dependency on empty GUID.
- Cannot add dependency on invalid path.
- Cannot add custom dependency on an empty custom dependency.
- Cannot add dependency on invalid ArtifactKey.
- A shader '{assetPath}' cannot depend on the 'srp/default-sha
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/a79bce4248142355.
Report an issue: GitHub.