{"record":{"id":"c3c4e0087758057b","repo":"Unity-Technologies/UnityCsReference","slug":"folder-relative-path-cannot-start-with-a-slash","errorCode":null,"errorMessage":"Folder relative path cannot start with a slash.","messagePattern":"Folder relative path cannot start with a slash\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/ScriptableSingletonDictionary.cs","lineNumber":31,"sourceCode":"{\n    // Use the LibraryFolderPathAttribute when you want to have your scriptable singleton dictionary\n    // to persist between unity sessions.\n    // Example: [LibraryFolderPathAttribute(\"EditorWindows\")]\n    [AttributeUsage(AttributeTargets.Class)]\n    class LibraryFolderPathAttribute : Attribute\n    {\n        public string folderPath { get; set; }\n        public LibraryFolderPathAttribute(string relativePath)\n        {\n            if (string.IsNullOrEmpty(relativePath))\n            {\n                Debug.LogError(\"Invalid relative path! (its null or empty)\");\n                return;\n            }\n\n            // We do not want a slash as first char.\n            if (relativePath[0] == '/')\n                throw new ArgumentException(\"Folder relative path cannot start with a slash.\");\n\n            folderPath = \"Library/\" + relativePath;\n        }\n    }\n\n    internal abstract partial class ScriptableSingletonDictionary<TDerived, TValue> : ScriptableObject\n        where TDerived : ScriptableObject\n        where TValue : ScriptableObject\n    {\n        [AutoStaticsCleanupOnCodeReload]\n        private static TDerived s_Instance;\n        static readonly string k_Extension = \".pref\";\n\n        protected string m_PreferencesFileName;\n\n        public static TDerived instance\n        {\n            get","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/ScriptableSingletonDictionary.cs#L13-L49","documentation":"Thrown by LibraryFolderPathAttribute constructor when relativePath starts with a forward slash. The attribute prefixes the path with 'Library/' internally, so a leading slash would create a malformed path (e.g., 'Library//foo'). An empty or null path is handled separately via Debug.LogError (not an exception), but a leading slash is a hard error.","triggerScenarios":"Declaring [LibraryFolderPath(\"/MyFolder\")] on a ScriptableSingletonDictionary subclass. Path constructed by concatenating a separator at the front.","commonSituations":"Copy-paste of absolute-style paths into the attribute. Convention mismatch where developers assume a leading slash is needed like in Unix paths.","solutions":["Remove the leading slash from the relative path.","Use a relative path without a leading separator, e.g., [LibraryFolderPath(\"MyFolder\")].","Trim leading slashes if the path is dynamically generated: path.TrimStart('/')."],"exampleFix":"// before\n[LibraryFolderPath(\"/MyFolder\")]\ninternal class MyData : ScriptableSingletonDictionary<MyData, MyType> { }\n\n// after\n[LibraryFolderPath(\"MyFolder\")]\ninternal class MyData : ScriptableSingletonDictionary<MyData, MyType> { }","handlingStrategy":"validation","validationCode":"// Compile-time: ensure the path does not start with '/'.\n// [LibraryFolderPath(\"MyFolder\")]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never prefix LibraryFolderPath paths with a leading slash.","If generating paths dynamically, call TrimStart('/') before use."],"tags":["unity","scriptable-singleton","editor","validation","path"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}