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

  1. Add [LibraryFolderPath("YourFolderName")] to the derived class.
  2. Ensure the attribute is on the class declaration, not a field or method.
  3. 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

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


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/31cbdd3ef0812233. Report an issue: GitHub.