stride3d/stride · error · ArgumentOutOfRangeException

SourceFolder.Folder cannot be null

Error message

SourceFolder.Folder cannot be null

What it means

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.

Solutions

  1. Set a valid (non-null) UFile/UDirectory Path on the AssetFolder before adding it
  2. Construct the AssetFolder with its path in the constructor instead of default-initializing it
  3. When cloning packages, ensure source folders were fully initialized
  4. Filter or log any folder with null Path before calling Add

Example fix

// before
var folder = new AssetFolder();
package.Folders.Add(folder); // Path == null
// after
var folder = new AssetFolder { Path = "/assets/levels" };
package.Folders.Add(folder);
Defensive patterns

Strategy: validation

Validate before calling

if (folder?.Path == null)
    throw new InvalidOperationException("AssetFolder must have a Path before being added");
folders.Add(folder);

Type guard

static bool CanAdd(AssetFolder f) => f?.Path != null;

Try / catch

try { folders.Add(folder); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "item")
{ log.Error($"Folder '{folder?.Name}' has null path"); }

Prevention

When it happens

Trigger: Calling Add (directly or via CloneTo) with an AssetFolder constructed without a path, or whose Path was never initialized/defaulted.

Common situations: Building folder structures programmatically and forgetting to set Path; deserializing partially populated folder objects; cloning packages whose folders list contains an uninitialized folder.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/379f6839a6f9be1b. Report an issue: GitHub.

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/AssetFolderCollection.cs:35

public sealed class AssetFolderCollection : IList<AssetFolder>, IReadOnlyList<AssetFolder>
{
    private readonly List<AssetFolder> folders;

    /// <summary>
    /// Initializes a new instance of the <see cref="AssetFolderCollection"/> class.
    /// </summary>
    public AssetFolderCollection()
    {
        folders = [];
    }

    /// <inheritdoc/>
    public void Add(AssetFolder item)
    {
        ArgumentNullException.ThrowIfNull(item);
        if (item.Path == null)
        {
            throw new ArgumentOutOfRangeException(nameof(item), "SourceFolder.Folder cannot be null");
        }

        // If a folder is already added, use it and squash the item to add to the existing folder.
        var existingFolder = Find(item.Path);
        if (existingFolder == null)
        {
            folders.Add(item);
        }
    }

    public AssetFolder? Find(UDirectory folder)
    {
        return folders.FirstOrDefault(sourceFolder => sourceFolder.Path == folder);
    }

    /// <inheritdoc/>
    public void Clear()
    {

View on GitHub (pinned to 96fad776d2)