Unity-Technologies/UnityCsReference · error · ArgumentException
The LibraryFolderPathAttribute[] attribute is required for t
Error message
The LibraryFolderPathAttribute[] attribute is required for this class.
What it means
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.
Source
Thrown at Editor/Mono/ScriptableSingletonDictionary.cs:146
m_PreferencesFileName = preferencesFileName;
return value ?? CreateNewValue();
}
private string GetFolderPath()
{
Type type = this.GetType();
object[] attributes = type.GetCustomAttributes(true);
foreach (object attr in attributes)
{
if (attr is LibraryFolderPathAttribute)
{
LibraryFolderPathAttribute f = attr as LibraryFolderPathAttribute;
return f.folderPath;
}
}
// The folder path attribute is required.
throw new ArgumentException("The LibraryFolderPathAttribute[] attribute is required for this class.");
}
}
}
View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
internal class MyRegistry : ScriptableSingletonDictionary<MyRegistry, MyEntry> { }
// after
[LibraryFolderPath("MyRegistry")]
internal class MyRegistry : ScriptableSingletonDictionary<MyRegistry, MyEntry> { } Defensive patterns
Strategy: validation
Validate before calling
// Compile-time: ensure every ScriptableSingletonDictionary subclass has:
// [LibraryFolderPath("FolderName")] Type guard
static bool HasLibraryFolderPath(Type t)
=> t.GetCustomAttributes(typeof(LibraryFolderPathAttribute), true).Length > 0; Prevention
- Always add [LibraryFolderPath] to ScriptableSingletonDictionary subclasses.
- Add a unit test or reflection check to verify all derived types carry the attribute.
When it happens
Trigger: Deriving from ScriptableSingletonDictionary<TDerived, TValue> without adding the [LibraryFolderPath] attribute. The attribute was removed during refactoring or never added for a new subclass.
Common situations: Creating a new ScriptableSingletonDictionary subclass and forgetting the attribute. Renaming or removing the attribute in a refactor without updating all derived classes.
Related errors
- Invalid relative path (it is empty)
- Folder relative path cannot start with a slash.
- visibleColumns should should not be set to an empty array. A
- Error while reading window layout: no main window found
- Attempting to set an incorrect number of icons for {namedBui
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/31cbdd3ef0812233.
Report an issue: GitHub.