{"record":{"id":"532ecb8a7e8359a8","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-add-dependency-on-invalid-path","errorCode":null,"errorMessage":"Cannot add dependency on invalid path.","messagePattern":"Cannot add dependency on invalid path\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetPipeline/AssetImportContext.bindings.cs","lineNumber":65,"sourceCode":"        public void AddObjectToAsset(string identifier, Object obj)\n        {\n            AddObjectToAsset(identifier, obj, null);\n        }\n\n        [FreeFunction(\"AssetImportContextBindings::GetObjects\", HasExplicitThis = true)]\n        public extern void GetObjects([NotNull][Out] List<Object> objects);\n\n        [NativeMethod(ThrowsException = true)]\n        public extern void AddObjectToAsset(string identifier, Object obj, Texture2D thumbnail);\n\n        // Create a dependency against the contents of the source asset at the provided path\n        // * if the asset at the path changes, it will trigger an import\n        // * 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","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetPipeline/AssetImportContext.bindings.cs#L47-L83","documentation":"AssetImportContext.DependsOnSourceAsset(string path) registers a source-level dependency: if the asset at the given path changes or moves, the importing asset is re-imported. It throws ArgumentNullException with message 'Cannot add dependency on invalid path.' when path is null or empty, because an empty path cannot resolve to a valid source asset and would silently create a dead dependency.","triggerScenarios":"Calling context.DependsOnSourceAsset(null) or context.DependsOnSourceAsset(\"\") from within a ScriptedImporter's OnImportAsset method. The path typically comes from a serialized reference, a computed GUID-to-path lookup, or a sub-asset path that can be empty if the source data is malformed.","commonSituations":"Custom ScriptedImporters that declare dependencies on other assets (textures, shaders, data files) where the dependency path is derived from the imported file's content and can be null/empty if the source file references a missing or unconfigured asset.","solutions":["Validate the path before calling: if (!string.IsNullOrEmpty(depPath)) context.DependsOnSourceAsset(depPath).","Log a warning and skip the dependency if the source file references an empty path, treating it as optional or malformed input.","Ensure dependency paths are resolved through AssetDatabase.GUIDToAssetPath with GUID validation first."],"exampleFix":"// before\ncontext.DependsOnSourceAsset(referencedPath);\n\n// after\nif (!string.IsNullOrEmpty(referencedPath))\n    context.DependsOnSourceAsset(referencedPath);\nelse\n    Debug.LogWarning($\"{context.assetPath}: skipping empty source dependency\");","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrEmpty(depPath))\n    context.DependsOnSourceAsset(depPath);\nelse\n    Debug.LogWarning($\"{context.assetPath}: empty source dependency path\");","typeGuard":"static bool IsValidDependencyPath(string path) => !string.IsNullOrEmpty(path);","tryCatchPattern":"try { context.DependsOnSourceAsset(path); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"path\")\n{ Debug.LogWarning($\"Skipped source dependency: {ex.Message}\"); }","preventionTips":["Validate all dependency paths in OnImportAsset before registering them","Resolve paths via AssetDatabase.GUIDToAssetPath and check for empty","Log skipped dependencies to catch malformed source-file references early"],"tags":["unity","csharp","asset-pipeline","scripted-importer","dependency-graph","null-check"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}