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
- Populate the collection with at least one element before calling the API that validates it
- Check collection.Count > 0 (or collection.Any()) before invoking, and handle the empty case explicitly in your caller
- Verify the upstream data source (config, file, query) actually produced items; fix the loading step if it silently returns an empty collection
- 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
- Check Count/Any() before calls guarded by NotEmpty
- Never forward results of filtering operations without verifying they matched
- Default-initialize collection fields with required items when the contract forbids emptiness
- Add unit tests covering the empty-collection path
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
- There must be two and only two input values for Int2.
- Indices for Int2 run from 0 to 1, inclusive.
- There must be three and only three input values for Int3.
- Indices for Int3 run from 0 to 2, inclusive.
- Indices for Int4 run from 0 to 3, inclusive.
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)