{"record":{"id":"4b79f097faf92fd6","repo":"stride3d/stride","slug":"argument-must-be-of-type-angle","errorCode":null,"errorMessage":"Argument must be of type Angle.","messagePattern":"Argument must be of type Angle\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/AngleSingle.cs","lineNumber":626,"sourceCode":"    /// Compares this instance to a specified object and returns an integer that\n    /// indicates whether the value of this instance is less than, equal to, or greater\n    /// than the value of the specified object.\n    /// </summary>\n    /// <param name=\"other\">The object to compare.</param>\n    /// <returns>\n    /// A signed integer that indicates the relationship of the current instance\n    /// to the obj parameter. If the value is less than zero, the current instance\n    /// is less than the other. If the value is zero, the current instance is equal\n    /// to the other. If the value is greater than zero, the current instance is\n    /// greater than the other.\n    /// </returns>\n    public readonly int CompareTo(object? other)\n    {\n        if (other == null)\n            return 1;\n\n        if (other is not AngleSingle single)\n            throw new ArgumentException(\"Argument must be of type Angle.\", nameof(other));\n\n        float radians = single.Radians;\n\n        if (Radians > radians)\n            return 1;\n\n        if (Radians < radians)\n            return -1;\n\n        return 0;\n    }\n\n    /// <summary>\n    /// Compares this instance to a second Stride.Core.Mathematics.AngleSingle and returns\n    /// an integer that indicates whether the value of this instance is less than,\n    /// equal to, or greater than the value of the specified object.\n    /// </summary>\n    /// <param name=\"other\">The object to compare.</param>","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/AngleSingle.cs#L608-L644","documentation":"AngleSingle.CompareTo(object) requires the boxed argument to be an AngleSingle; any other non-null type causes an ArgumentException. This is the non-generic IComparable implementation used for ordering angles.","triggerScenarios":"Passing a boxed value of another type (float, double, or a different struct) to CompareTo, e.g. through sorting with a non-generic IComparer, reflection, or comparing an Angle with a plain number.","commonSituations":"Legacy IComparable-based collections (ArrayList, Array.Sort without comparer) mixing types; data binding frameworks boxing values; converting code that previously used raw floats.","solutions":["Pass an AngleSingle: use the generic IComparable<AngleSingle> (CompareTo(Angle)) instead of the object overload.","Convert floats first: new AngleSingle(value, AngleType.Radian).CompareTo(other).","Use typed collections/comparers (List<AngleSingle>, Comparer<AngleSingle>.Default).","In reflection/binding scenarios, type-check with 'is AngleSingle' before calling CompareTo."],"exampleFix":"// before\nobject a = 1.5f;\nangle.CompareTo(a); // ArgumentException\n// after\nangle.CompareTo(new AngleSingle(1.5f, AngleType.Radian));","handlingStrategy":"type-guard","validationCode":"if (other is not AngleSingle)\n    throw new ArgumentException($\"Expected AngleSingle, got {other?.GetType().Name}\", nameof(other));","typeGuard":"static bool IsAngle(object? o) => o is AngleSingle;","tryCatchPattern":"try { cmp = angle.CompareTo(boxed); }\ncatch (ArgumentException) { cmp = angle.CompareTo(Convert.ToSingle(boxed).ToRadianAngle()); }","preventionTips":["Use IComparable<AngleSingle>/typed comparers instead of the object overload","Box angles only at interop boundaries and unbox with 'is AngleSingle'","Prefer AngleSingle arithmetic over raw floats when ordering matters"],"tags":["math","dotnet","type-mismatch"],"backgroundTag":"type-mismatch","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"}