stride3d/stride · error · ArgumentException

The decimalPlaces should be greater or equal to zero.

Error message

The decimalPlaces should be greater or equal to zero.

What it means

DataMemberRangeAttribute(double minimum, int decimalPlaces) throws ArgumentException with 'The decimalPlaces should be greater or equal to zero.' when a negative decimalPlaces value is supplied. decimalPlaces controls rounding/step precision for range-validated members; a negative precision is meaningless, so the attribute constructor rejects it at decoration time.

Solutions

  1. Pass a non-negative decimalPlaces value (e.g. 0, 2, 3).
  2. Take Math.Abs or Math.Max(0, decimals) on the computed value before applying the attribute.
  3. Check constants used for decimalPlaces cannot be negative.

Example fix

// before
[DataMemberRange(0.0, -2)]
public float Opacity { get; set; }
// after
[DataMemberRange(0.0, 2)]
public float Opacity { get; set; }
Defensive patterns

Strategy: validation

Validate before calling

int decimals = ...;
if (decimals < 0)
    throw new ArgumentException("decimalPlaces must be >= 0");
// attribute usage is then safe:
// [DataMemberRange(minimum, decimals)]

Type guard

static bool HasValidDecimalPlaces(int d) => d >= 0;

Try / catch

try
{
    var attr = new DataMemberRangeAttribute(minimum, decimalPlaces);
}
catch (ArgumentException ex)
{
    log.Error("Invalid DataMemberRange configuration: " + ex.Message);
}

Prevention

When it happens

Trigger: Decorating a property/field with [DataMemberRange(0.0, -2)] or otherwise passing a negative second argument to the two-parameter constructor. It throws when the attribute is constructed (first instantiation of the attribute).

Common situations: Configuring numeric UI editors/serialization ranges in Stride (formerly Xenko) assets; sign mistakes when a value like decimals = -1 came from another constant.

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/aceaefd22f6914b3. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core/Annotations/DataMemberRangeAttribute.cs:21

namespace Stride.Core.Annotations;

/// <summary>
/// Defines range values for a property or field.
/// </summary>
/// <remarks><see cref="Minimum"/>, <see cref="Maximum"/> and <see cref="SmallStep"/> must have the same type</remarks>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class DataMemberRangeAttribute : Attribute
{
    /// <summary>
    /// Initializes a new instance of the <see cref="DataMemberRangeAttribute" /> class.
    /// </summary>
    /// <param name="minimum">The minimum.</param>
    /// <param name="decimalPlaces">The decimal places</param>
    public DataMemberRangeAttribute(double minimum, int decimalPlaces)
    {
        if (double.IsNaN(minimum)) throw new ArgumentOutOfRangeException(nameof(minimum));
        if (decimalPlaces < 0) throw new ArgumentException("The decimalPlaces should be greater or equal to zero.", nameof(decimalPlaces));
        Minimum = minimum;
        DecimalPlaces = decimalPlaces;
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="DataMemberRangeAttribute" /> class.
    /// </summary>
    /// <param name="minimum">The minimum.</param>
    /// <param name="maximum">The maximum.</param>
    /// <param name="smallStep">The minimum step used to go from minimum to maximum.</param>
    /// <param name="largeStep">The maximum step used to go from minimum to maximum.</param>
    /// <param name="decimalPlaces">The decimal places.</param>
    public DataMemberRangeAttribute(double minimum, double maximum, double smallStep, double largeStep, int decimalPlaces)
        : this(minimum, decimalPlaces)
    {
        if (double.IsNaN(maximum)) throw new ArgumentOutOfRangeException(nameof(maximum));
        if (minimum > maximum) throw new ArgumentException("The minimum should be lesser or equal to the maximum.", nameof(minimum));
        if (double.IsNaN(smallStep)) throw new ArgumentOutOfRangeException(nameof(smallStep));

View on GitHub (pinned to 96fad776d2)