{"record":{"id":"04968925734c5c23","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-add-dependency-on-invalid-artifactkey","errorCode":null,"errorMessage":"Cannot add dependency on invalid ArtifactKey.","messagePattern":"Cannot add dependency on invalid ArtifactKey\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetPipeline/AssetImportContext.bindings.cs","lineNumber":152,"sourceCode":"        public byte[] GetArtifactData(ArtifactKey key, string fileName)\n        {\n            return GetArtifactData_ArtifactKey(key, fileName);\n        }\n\n        [Obsolete(\"GetOutputArtifactFilePath has been deprecated. Use SetOutputArtifactData to write artifact data from memory, or SetOutputArtifactFile to copy artifact data from a file instead.\")]\n        [NativeName(\"GetOutputArtifactFilePath_Binding\")]\n        public extern string GetOutputArtifactFilePath(string fileName);\n\n        [NativeName(\"DependsOnImportedAsset\")]\n        private extern void DependsOnImportedAssetInternal(string path);\n\n        public extern Object GetReferenceToAssetMainObject(string path);\n\n        public void DependsOnArtifact(ArtifactKey key)\n        {\n            if (!key.isValid)\n            {\n                throw new ArgumentNullException(\"key\", \"Cannot add dependency on invalid ArtifactKey.\");\n            }\n\n            DependsOnArtifactInternal(key);\n        }\n\n        [NativeName(\"DependsOnArtifact\")]\n        private extern void DependsOnArtifactInternal(ArtifactKey key);\n\n        public void DependsOnArtifact(GUID guid)\n        {\n            if (guid.Empty())\n            {\n                throw new ArgumentNullException(\"guid\", \"Cannot add artifact dependency on empty GUID.\");\n            }\n\n            DependsOnArtifactInternalGUID(guid);\n        }\n","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetPipeline/AssetImportContext.bindings.cs#L134-L170","documentation":"AssetImportContext.DependsOnArtifact(ArtifactKey key) registers a dependency on the import artifact identified by an ArtifactKey. It throws ArgumentNullException with message 'Cannot add dependency on invalid ArtifactKey.' when key.isValid is false. ArtifactKey wraps a GUID and import settings hash; an invalid key means the GUID is empty or the hash is unset, so no artifact can be resolved.","triggerScenarios":"Calling context.DependsOnArtifact(key) where key was constructed from an empty GUID, or where the ArtifactKey was default-initialized (all fields zero). This overload is distinct from the GUID overload (error 29) and the string path overload (error 30).","commonSituations":"Advanced ScriptedImporters or internal editor tools that track artifact-level dependencies (e.g., depending on a shader's compiled variant output). The ArtifactKey can be invalid if it was built from a stale or unresolved asset reference.","solutions":["Check key.isValid before calling: if (key.isValid) context.DependsOnArtifact(key).","Construct ArtifactKey only from validated, non-empty GUIDs and correct import settings.","Fall back to DependsOnArtifact(GUID) or DependsOnArtifact(string path) if you only have partial key data."],"exampleFix":"// before\ncontext.DependsOnArtifact(artifactKey);\n\n// after\nif (artifactKey.isValid)\n    context.DependsOnArtifact(artifactKey);\nelse\n    Debug.LogWarning($\"{context.assetPath}: invalid ArtifactKey, skipping artifact dependency\");","handlingStrategy":"validation","validationCode":"if (key.isValid)\n    context.DependsOnArtifact(key);\nelse\n    Debug.LogWarning($\"{context.assetPath}: invalid ArtifactKey\");","typeGuard":"static bool IsValidArtifactKey(ArtifactKey key) => key.isValid;","tryCatchPattern":"try { context.DependsOnArtifact(key); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"key\")\n{ Debug.LogWarning($\"Skipped artifact dependency: {ex.Message}\"); }","preventionTips":["Check key.isValid before all ArtifactKey-based dependency calls","Construct ArtifactKey only from validated GUIDs and correct settings hashes","Fall back to GUID or path overloads if ArtifactKey data is incomplete"],"tags":["unity","csharp","asset-pipeline","scripted-importer","dependency-graph","artifact-key","validation"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}