stride3d/stride · error · ArgumentException

cannot be equal to .

Error message

{paramName} cannot be equal to {value}.

What it means

ArgumentCheck.NotEquals<T> throws ArgumentException when the variable equals the forbidden value under EqualityComparer<T>.Default. It is a guard against assigning placeholder/sentinel values (e.g. default(T), null, or a specific disallowed constant) to a parameter.

Solutions

  1. Ensure the variable holds a real value different from the forbidden one before the call
  2. If variable is an identifier, confirm it was assigned after creation/persistence rather than left at default
  3. Check the equality semantics: if a custom Equals makes them 'equal' unexpectedly, fix the type's Equals/GetHashCode
  4. If equality with that value is actually acceptable, remove the NotEquals guard or pass the correct parameter

Example fix

// before
var id = Guid.Empty;
ArgumentCheck.NotEquals(id, Guid.Empty, nameof(id));
// after
var id = entity?.Id ?? throw new InvalidOperationException("Entity must be persisted first");
ArgumentCheck.NotEquals(id, Guid.Empty, nameof(id));
Defensive patterns

Strategy: validation

Validate before calling

if (EqualityComparer<T>.Default.Equals(value, forbidden))
    throw new ArgumentException($"{nameof(value)} must not be {forbidden}", nameof(value));

Try / catch

try { NotEquals(id, Guid.Empty, nameof(id)); }
catch (ArgumentException ex) when (ex.ParamName == nameof(id))
{
    // assign a real id or abort the operation
}

Prevention

When it happens

Trigger: Calling ArgumentCheck.NotEquals(variable, value, variableName) where variable compares equal to value, e.g. passing default(Guid) (Guid.Empty), 0, or null for a reference-type T to a parameter that forbids exactly that value.

Common situations: Passing an uninitialized identifier (Guid.Empty, 0) because an entity was never persisted; a struct field left at default(T); a deserialized object whose id defaulted to the disallowed sentinel.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

        /// <summary>
        /// Checks whether the <paramref name="variable"/> is different from <paramref name="value"/>.
        /// Otherwise throws an exception.
        /// </summary>
        /// <typeparam name="T">The type of the <paramref name="variable"/>.</typeparam>
        /// <param name="variable">The value to check.</param>
        /// <param name="value">The value to compare to for inequality.</param>
        /// <param name="variableName">The name of the variable being checked.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="variable"/> is equal to the <paramref name="value"/>.
        /// </exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static void NotEquals<T>(T variable, T value, string variableName)
        {
            var paramName = variableName ?? "The variable";
            if (EqualityComparer<T>.Default.Equals(variable, value))
            {
                throw new ArgumentException($"{paramName} cannot be equal to {value}.");
            }
        }

        /// <summary>
        /// Checks wether the <paramref name="variable"/> is not <see langword="null"/>.
        /// Otherwise throws an exception.
        /// </summary>
        /// <param name="variable">The value to check.</param>
        /// <param name="variableName">The name of the variable being checked.</param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="variable"/> cannot be <see langword="null"/>.
        /// </exception>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static void NotNull(object variable, string variableName)
        {
            var paramName = variableName ?? "The variable";
            if (null == variable)
            {

View on GitHub (pinned to 96fad776d2)