stride3d/stride · error · ArgumentOutOfRangeException

cannot be empty.

Error message

{paramName} cannot be empty.

What it means

ArgumentCheck.NotEmpty throws ArgumentOutOfRangeException when a collection-like argument (with a Count property) has zero elements. The library enforces the contract that the caller must pass a non-null, non-empty collection. The paramName defaults to "The collection" when no variable name is supplied.

Solutions

  1. Populate the collection with at least one element before calling the API that validates it
  2. Check collection.Count > 0 (or collection.Any()) before invoking, and handle the empty case explicitly in your caller
  3. Verify the upstream data source (config, file, query) actually produced items; fix the loading step if it silently returns an empty collection
  4. If an empty collection is legitimately valid, stop routing it through this API and handle it before the call

Example fix

// before
ProcessItems(new List<string>());
// after
var items = LoadItems();
if (items.Count == 0) { /* handle empty case */ return; }
ProcessItems(items);
Defensive patterns

Strategy: validation

Validate before calling

if (collection == null) throw new ArgumentNullException(nameof(collection));
if (collection.Count == 0) throw new ArgumentException("Collection must contain at least one item", nameof(collection));

Type guard

bool IsNonEmpty<T>(IReadOnlyCollection<T>? c) => c is { Count: > 0 };

Try / catch

try { NotEmpty(items, nameof(items)); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == nameof(items))
{
    // handle empty-collection case
}

Prevention

When it happens

Trigger: Calling ArgumentCheck.NotEmpty (IEnumerable or collection overloads at ArgumentCheck.cs:84) with a collection whose Count == 0, e.g. a fresh List<T>, an empty array, or the result of a filtering operation that matched nothing.

Common situations: Passing an empty list loaded from config or a database query that returned no rows; constructing an Asset/Package editor operation with no selected items; refactoring that changed a default field initializer from a populated list to a new empty one.

Related errors


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

Appendix: source

Thrown at sources/editor/Stride.Core.Assets.Editor/ArgumentCheck.cs:84

        /// Otherwise throws an exception.
        /// </summary>
        /// <param name="collection">The collection to check.</param>
        /// <param name="variableName">The name of the variable being checked.</param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="collection"/> cannot be <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// The <paramref name="collection"/> is empty.
        /// </exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static void NotEmpty(ICollection collection, string variableName)
        {
            var paramName = variableName ?? "The collection";
            // collection cannot be null
            NotNull(collection, "collection");
            if (collection.Count == 0)
            {
                throw new ArgumentOutOfRangeException(paramName, $"{paramName} cannot be empty.");
            }
        }

        /// <summary>
        /// Checks wether the <paramref name="collection"/> is not empty.
        /// Otherwise throws an exception.
        /// </summary>
        /// <typeparam name="T">The type of the <paramref name="collection"/>.</typeparam>
        /// <param name="collection">The collection to check.</param>
        /// <param name="variableName">The name of the variable being checked.</param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="collection"/> cannot be <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// The <paramref name="collection"/> is empty.
        /// </exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static void NotEmpty<T>(ICollection<T> collection, string variableName)

View on GitHub (pinned to 96fad776d2)