{"record":{"id":"aceaefd22f6914b3","repo":"stride3d/stride","slug":"the-decimalplaces-should-be-greater-or-equal-to-zero","errorCode":null,"errorMessage":"The decimalPlaces should be greater or equal to zero.","messagePattern":"The decimalPlaces should be greater or equal to zero\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Annotations/DataMemberRangeAttribute.cs","lineNumber":21,"sourceCode":"\nnamespace Stride.Core.Annotations;\n\n/// <summary>\n/// Defines range values for a property or field.\n/// </summary>\n/// <remarks><see cref=\"Minimum\"/>, <see cref=\"Maximum\"/> and <see cref=\"SmallStep\"/> must have the same type</remarks>\n[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]\npublic class DataMemberRangeAttribute : Attribute\n{\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"DataMemberRangeAttribute\" /> class.\n    /// </summary>\n    /// <param name=\"minimum\">The minimum.</param>\n    /// <param name=\"decimalPlaces\">The decimal places</param>\n    public DataMemberRangeAttribute(double minimum, int decimalPlaces)\n    {\n        if (double.IsNaN(minimum)) throw new ArgumentOutOfRangeException(nameof(minimum));\n        if (decimalPlaces < 0) throw new ArgumentException(\"The decimalPlaces should be greater or equal to zero.\", nameof(decimalPlaces));\n        Minimum = minimum;\n        DecimalPlaces = decimalPlaces;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"DataMemberRangeAttribute\" /> class.\n    /// </summary>\n    /// <param name=\"minimum\">The minimum.</param>\n    /// <param name=\"maximum\">The maximum.</param>\n    /// <param name=\"smallStep\">The minimum step used to go from minimum to maximum.</param>\n    /// <param name=\"largeStep\">The maximum step used to go from minimum to maximum.</param>\n    /// <param name=\"decimalPlaces\">The decimal places.</param>\n    public DataMemberRangeAttribute(double minimum, double maximum, double smallStep, double largeStep, int decimalPlaces)\n        : this(minimum, decimalPlaces)\n    {\n        if (double.IsNaN(maximum)) throw new ArgumentOutOfRangeException(nameof(maximum));\n        if (minimum > maximum) throw new ArgumentException(\"The minimum should be lesser or equal to the maximum.\", nameof(minimum));\n        if (double.IsNaN(smallStep)) throw new ArgumentOutOfRangeException(nameof(smallStep));","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Annotations/DataMemberRangeAttribute.cs#L3-L39","documentation":"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.","triggerScenarios":"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).","commonSituations":"Configuring numeric UI editors/serialization ranges in Stride (formerly Xenko) assets; sign mistakes when a value like decimals = -1 came from another constant.","solutions":["Pass a non-negative decimalPlaces value (e.g. 0, 2, 3).","Take Math.Abs or Math.Max(0, decimals) on the computed value before applying the attribute.","Check constants used for decimalPlaces cannot be negative."],"exampleFix":"// before\n[DataMemberRange(0.0, -2)]\npublic float Opacity { get; set; }\n// after\n[DataMemberRange(0.0, 2)]\npublic float Opacity { get; set; }","handlingStrategy":"validation","validationCode":"int decimals = ...;\nif (decimals < 0)\n    throw new ArgumentException(\"decimalPlaces must be >= 0\");\n// attribute usage is then safe:\n// [DataMemberRange(minimum, decimals)]","typeGuard":"static bool HasValidDecimalPlaces(int d) => d >= 0;","tryCatchPattern":"try\n{\n    var attr = new DataMemberRangeAttribute(minimum, decimalPlaces);\n}\ncatch (ArgumentException ex)\n{\n    log.Error(\"Invalid DataMemberRange configuration: \" + ex.Message);\n}","preventionTips":["Never pass constants that can be negative as decimalPlaces.","Remember attributes are evaluated at type-load/metadata time, so test attribute usage in unit tests.","Keep decimalPlaces a small non-negative literal (0–6) in asset code."],"tags":["invalid-argument-value","csharp","attributes"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}