{"record":{"id":"a79bce4248142355","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-add-source-dependency-on-empty-guid","errorCode":null,"errorMessage":"Cannot add source dependency on empty GUID.","messagePattern":"Cannot add source dependency on empty GUID\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetPipeline/AssetImportContext.bindings.cs","lineNumber":78,"sourceCode":"        // * if the asset at the path moves, it will trigger an import\n        public void DependsOnSourceAsset(string path)\n        {\n            if (string.IsNullOrEmpty(path))\n            {\n                throw new ArgumentNullException(\"path\", \"Cannot add dependency on invalid path.\");\n            }\n\n            DependsOnSourceAssetInternal(path);\n        }\n\n        [NativeName(\"DependsOnSourceAsset\")]\n        private extern void DependsOnSourceAssetInternal(string path);\n\n        public void DependsOnSourceAsset(GUID guid)\n        {\n            if (guid.Empty())\n            {\n                throw new ArgumentNullException(\"guid\", \"Cannot add source dependency on empty GUID.\");\n            }\n\n            DependsOnSourceAssetInternalGUID(guid);\n        }\n\n        [NativeName(\"DependsOnSourceAsset\")]\n        private extern void DependsOnSourceAssetInternalGUID(GUID guid);\n\n        [NativeName(\"GetFolderEntries\")]\n        internal extern GUID[] GetFolderEntries(GUID folder);\n\n        internal void DependsOnImportedAsset(string path)\n        {\n            if (string.IsNullOrEmpty(path))\n            {\n                throw new ArgumentNullException(\"path\", \"Cannot add dependency on invalid path.\");\n            }\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetPipeline/AssetImportContext.bindings.cs#L60-L96","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\ncontext.DependsOnSourceAsset(referencedGuid);\n\n// after\nif (!referencedGuid.Empty())\n    context.DependsOnSourceAsset(referencedGuid);\nelse\n    Debug.LogWarning($\"{context.assetPath}: source dependency GUID is empty, skipping\");","handlingStrategy":"validation","validationCode":"if (!guid.Empty())\n    context.DependsOnSourceAsset(guid);\nelse\n    Debug.LogWarning($\"{context.assetPath}: empty source dependency GUID\");","typeGuard":"static bool IsValidGuid(GUID guid) => !guid.Empty();","tryCatchPattern":"try { context.DependsOnSourceAsset(guid); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"guid\")\n{ Debug.LogWarning($\"Skipped source dependency: {ex.Message}\"); }","preventionTips":["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"],"tags":["unity","csharp","asset-pipeline","scripted-importer","dependency-graph","guid","null-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}