{"record":{"id":"31cbdd3ef0812233","repo":"Unity-Technologies/UnityCsReference","slug":"the-libraryfolderpathattribute-attribute-is-requ","errorCode":null,"errorMessage":"The LibraryFolderPathAttribute[] attribute is required for this class.","messagePattern":"The LibraryFolderPathAttribute\\[\\] attribute is required for this class\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/ScriptableSingletonDictionary.cs","lineNumber":146,"sourceCode":"            m_PreferencesFileName = preferencesFileName;\n            return value ?? CreateNewValue();\n        }\n\n        private string GetFolderPath()\n        {\n            Type type = this.GetType();\n            object[] attributes = type.GetCustomAttributes(true);\n            foreach (object attr in attributes)\n            {\n                if (attr is LibraryFolderPathAttribute)\n                {\n                    LibraryFolderPathAttribute f = attr as LibraryFolderPathAttribute;\n                    return f.folderPath;\n                }\n            }\n\n            // The folder path attribute is required.\n            throw new ArgumentException(\"The LibraryFolderPathAttribute[] attribute is required for this class.\");\n        }\n    }\n}\n","sourceCodeStart":128,"sourceCodeEnd":150,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/ScriptableSingletonDictionary.cs#L128-L150","documentation":"Thrown by ScriptableSingletonDictionary.GetFolderPath when the class type has no [LibraryFolderPath] attribute applied. The dictionary system needs a folder location under Library/ to store its serialized pref files; without the attribute, it cannot determine where to persist data. The method iterates all custom attributes and throws if none matches LibraryFolderPathAttribute.","triggerScenarios":"Deriving from ScriptableSingletonDictionary<TDerived, TValue> without adding the [LibraryFolderPath] attribute. The attribute was removed during refactoring or never added for a new subclass.","commonSituations":"Creating a new ScriptableSingletonDictionary subclass and forgetting the attribute. Renaming or removing the attribute in a refactor without updating all derived classes.","solutions":["Add [LibraryFolderPath(\"YourFolderName\")] to the derived class.","Ensure the attribute is on the class declaration, not a field or method.","Check all ScriptableSingletonDictionary subclasses have the attribute when introducing new ones."],"exampleFix":"// before\ninternal class MyRegistry : ScriptableSingletonDictionary<MyRegistry, MyEntry> { }\n\n// after\n[LibraryFolderPath(\"MyRegistry\")]\ninternal class MyRegistry : ScriptableSingletonDictionary<MyRegistry, MyEntry> { }","handlingStrategy":"validation","validationCode":"// Compile-time: ensure every ScriptableSingletonDictionary subclass has:\n// [LibraryFolderPath(\"FolderName\")]","typeGuard":"static bool HasLibraryFolderPath(Type t)\n    => t.GetCustomAttributes(typeof(LibraryFolderPathAttribute), true).Length > 0;","tryCatchPattern":null,"preventionTips":["Always add [LibraryFolderPath] to ScriptableSingletonDictionary subclasses.","Add a unit test or reflection check to verify all derived types carry the attribute."],"tags":["unity","scriptable-singleton","editor","validation","configuration"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}