stride3d/stride · error · ArgumentOutOfRangeException

This method must be invoked with at least one property name.

Error message

This method must be invoked with at least one property name.

What it means

The protected SetValue<T>(ref T, T, Action, params string[]) overload notifies change events for the given property names; calling it with zero names leaves nothing to notify, so it throws ArgumentOutOfRangeException.

Solutions

  1. Pass at least one property name, typically nameof(YourProperty)
  2. Validate dynamically built name arrays are non-empty before calling
  3. Split empty-array handling into a separate no-notify update path if no notification is desired

Example fix

// before
SetValue(ref _name, value);
// after
SetValue(ref _name, value, nameof(Name));
Defensive patterns

Strategy: validation

Validate before calling

if (propertyNames == null || propertyNames.Length == 0)
    throw new ArgumentException("At least one property name is required", nameof(propertyNames));
SetValue(ref _field, value, propertyNames);

Try / catch

try { SetValue(ref _field, value, names); }
catch (ArgumentOutOfRangeException ex) { log.Error(ex, "SetValue called without property names"); }

Prevention

When it happens

Trigger: Calling SetValue(ref field, value, updateAction) with an empty params string[] propertyNames — e.g. forwarding an empty property-name array or forgetting the name entirely.

Common situations: Refactoring a property setter and dropping the nameof(Property) argument; dynamically built property-name arrays that end up empty.

Related errors


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

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation/ViewModels/ViewModelBase.cs:124

    {
        return SetValue(ref field, value, updateAction, [propertyName]);
    }

    /// <summary>
    /// Sets the value of a field to the given value. Both values are compared with the default <see cref="EqualityComparer{T}"/>, and if they are equals,
    /// this method does nothing. If they are different, the <see cref="PropertyChanging"/> event will be raised first, then the field value will be modified.
    /// The given update action will be executed and finally the <see cref="PropertyChanged"/> event will be raised.
    /// </summary>
    /// <typeparam name="T">The type of the field.</typeparam>
    /// <param name="field">A reference to the field to set.</param>
    /// <param name="value">The new value to set.</param>
    /// <param name="updateAction">The update action to execute after setting the value. Can be <c>null</c>.</param>
    /// <param name="propertyNames">The names of the properties that must be notified as changing/changed. At least one property name must be provided.</param>
    /// <returns><c>True</c> if the field was modified and events were raised, <c>False</c> if the new value was equal to the old one and nothing was done.</returns>
    protected virtual bool SetValue<T>([NotNullIfNotNull(nameof(value))] ref T field, T value, Action? updateAction, params string[] propertyNames)
    {
        if (propertyNames.Length == 0)
            throw new ArgumentOutOfRangeException(nameof(propertyNames), "This method must be invoked with at least one property name.");

        if (!EqualityComparer<T>.Default.Equals(field, value))
        {
            OnPropertyChanging(propertyNames);
            field = value;
            updateAction?.Invoke();
            OnPropertyChanged(propertyNames);
            return true;
        }

        return false;
    }

    /// <summary>
    /// Manages a property modification and its notifications. This method will invoke the provided update action. The <see cref="PropertyChanging"/>
    /// event will be raised prior to the update action, and the <see cref="PropertyChanged"/> event will be raised after.
    /// </summary>
    /// <param name="updateAction">The update action that will actually manage the update of the property.</param>

View on GitHub (pinned to 96fad776d2)