{"record":{"id":"f22da2d0169b1a06","repo":"Unity-Technologies/UnityCsReference","slug":"a-shader-assetpath-cannot-depend-on-the-srp-d","errorCode":null,"errorMessage":"A shader '{assetPath}' cannot depend on the 'srp/default-shader' custom dependency because this operation is unsupported.","messagePattern":"A shader '(.+?)' cannot depend on the 'srp/default-shader' custom dependency because this operation is unsupported\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Editor/Mono/AssetPipeline/AssetImportContext.bindings.cs","lineNumber":229,"sourceCode":"            if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(artifact.entityId, out string guidString, out long _)\n                || !GUID.TryParse(guidString, out GUID guid))\n            {\n                return;\n            }\n\n            DependsOnArtifact(guid);\n        }\n\n        public void DependsOnCustomDependency(string dependency)\n        {\n            if (string.IsNullOrEmpty(dependency))\n            {\n                throw new ArgumentNullException(\"dependency\", \"Cannot add custom dependency on an empty custom dependency.\");\n            }\n\n            if (string.CompareOrdinal(dependency,\"srp/default-shader\") == 0 && assetPath.EndsWith(\".shader\", StringComparison.OrdinalIgnoreCase))\n            {\n                throw new Exception($\"A shader '{assetPath}' cannot depend on the 'srp/default-shader' custom dependency because this operation is unsupported.\");\n            }\n\n            DependsOnCustomDependencyInternal(dependency);\n        }\n\n        [NativeName(\"DependsOnCustomDependency\")]\n        private extern void DependsOnCustomDependencyInternal(string path);\n\n        extern void AddImportLog(string msg, string file, int line, ImportLogFlags flags, UnityEngine.Object obj);\n\n        void AddImportLog(string msg, ImportLogFlags flags, UnityEngine.Object obj)\n        {\n            var st = new StackTrace(2, true);\n            var sf = st.GetFrame(0);\n            AddImportLog(msg, sf.GetFileName(), sf.GetFileLineNumber(), flags, obj);\n        }\n\n        public void LogImportError(string msg, UnityEngine.Object obj = null)","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/AssetPipeline/AssetImportContext.bindings.cs#L211-L247","documentation":"AssetImportContext.DependsOnCustomDependency throws a plain Exception (not ArgumentNullException) with an interpolated message when a shader asset (.shader file) attempts to depend on the reserved custom dependency 'srp/default-shader'. This restriction exists because the SRP default shader dependency is a system-level key that shaders themselves must not depend on — it would create a circular or unsupported dependency in the shader import pipeline. The check uses string.CompareOrdinal for exact matching and assetPath.EndsWith('.shader').","triggerScenarios":"Calling context.DependsOnCustomDependency(\"srp/default-shader\") from a ScriptedImporter whose assetPath ends with '.shader'. This can happen if a custom dependency name is dynamically built or if a generic importer incorrectly applies SRP-related dependencies to shader assets.","commonSituations":"Custom ScriptedImporters or post-processors that blanket-apply SRP dependencies to all assets including shaders. Also occurs after Unity version upgrades where the SRP default-shader dependency name was introduced as a reserved key, and older importer code was not updated to exclude shaders.","solutions":["Exclude shader assets from the 'srp/default-shader' dependency: check if assetPath ends with '.shader' before registering that specific dependency.","Use a different, non-reserved custom dependency name for shader-related cache invalidation.","Separate the dependency-registration logic by asset type so shaders never receive the reserved key."],"exampleFix":"// before\ncontext.DependsOnCustomDependency(\"srp/default-shader\");\n\n// after\nbool isShader = context.assetPath.EndsWith(\".shader\", StringComparison.OrdinalIgnoreCase);\nif (!isShader)\n    context.DependsOnCustomDependency(\"srp/default-shader\");","handlingStrategy":"validation","validationCode":"bool isShader = context.assetPath.EndsWith(\".shader\", StringComparison.OrdinalIgnoreCase);\nif (!(isShader && dependency == \"srp/default-shader\"))\n    context.DependsOnCustomDependency(dependency);","typeGuard":"static bool IsSafeCustomDependency(string assetPath, string dep)\n    => !(dep == \"srp/default-shader\" && assetPath.EndsWith(\".shader\", StringComparison.OrdinalIgnoreCase));","tryCatchPattern":"try { context.DependsOnCustomDependency(dependency); }\ncatch (Exception ex) when (ex.Message.Contains(\"srp/default-shader\"))\n{ Debug.LogWarning($\"Skipped reserved custom dependency for shader: {context.assetPath}\"); }","preventionTips":["Exclude .shader assets from the reserved 'srp/default-shader' dependency","Branch dependency registration by asset type","Use non-reserved custom dependency names for shader-related cache keys"],"tags":["unity","csharp","asset-pipeline","scripted-importer","custom-dependency","srp","shader","reserved-key"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}