{"record":{"id":"379f6839a6f9be1b","repo":"stride3d/stride","slug":"sourcefolder-folder-cannot-be-null","errorCode":null,"errorMessage":"SourceFolder.Folder cannot be null","messagePattern":"SourceFolder\\.Folder cannot be null","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/AssetFolderCollection.cs","lineNumber":35,"sourceCode":"public sealed class AssetFolderCollection : IList<AssetFolder>, IReadOnlyList<AssetFolder>\n{\n    private readonly List<AssetFolder> folders;\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"AssetFolderCollection\"/> class.\n    /// </summary>\n    public AssetFolderCollection()\n    {\n        folders = [];\n    }\n\n    /// <inheritdoc/>\n    public void Add(AssetFolder item)\n    {\n        ArgumentNullException.ThrowIfNull(item);\n        if (item.Path == null)\n        {\n            throw new ArgumentOutOfRangeException(nameof(item), \"SourceFolder.Folder cannot be null\");\n        }\n\n        // If a folder is already added, use it and squash the item to add to the existing folder.\n        var existingFolder = Find(item.Path);\n        if (existingFolder == null)\n        {\n            folders.Add(item);\n        }\n    }\n\n    public AssetFolder? Find(UDirectory folder)\n    {\n        return folders.FirstOrDefault(sourceFolder => sourceFolder.Path == folder);\n    }\n\n    /// <inheritdoc/>\n    public void Clear()\n    {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/AssetFolderCollection.cs#L17-L53","documentation":"AssetFolderCollection.Add rejects an AssetFolder whose Path is null, because folders in the collection are keyed by path; a path-less folder cannot be indexed or deduplicated. It throws ArgumentOutOfRangeException naming the 'item' parameter.","triggerScenarios":"Calling Add (directly or via CloneTo) with an AssetFolder constructed without a path, or whose Path was never initialized/defaulted.","commonSituations":"Building folder structures programmatically and forgetting to set Path; deserializing partially populated folder objects; cloning packages whose folders list contains an uninitialized folder.","solutions":["Set a valid (non-null) UFile/UDirectory Path on the AssetFolder before adding it","Construct the AssetFolder with its path in the constructor instead of default-initializing it","When cloning packages, ensure source folders were fully initialized","Filter or log any folder with null Path before calling Add"],"exampleFix":"// before\nvar folder = new AssetFolder();\npackage.Folders.Add(folder); // Path == null\n// after\nvar folder = new AssetFolder { Path = \"/assets/levels\" };\npackage.Folders.Add(folder);","handlingStrategy":"validation","validationCode":"if (folder?.Path == null)\n    throw new InvalidOperationException(\"AssetFolder must have a Path before being added\");\nfolders.Add(folder);","typeGuard":"static bool CanAdd(AssetFolder f) => f?.Path != null;","tryCatchPattern":"try { folders.Add(folder); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"item\")\n{ log.Error($\"Folder '{folder?.Name}' has null path\"); }","preventionTips":["Always construct AssetFolder with a path","Validate folders after deserialization before re-adding","Set Path at the single construction site rather than later"],"tags":["assets","null-path","argument-out-of-range"],"backgroundTag":"missing-required-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}