{"record":{"id":"4fca0f65271ecc63","repo":"Humanizr/Humanizer","slug":"object-is-not-a-byterate","errorCode":null,"errorMessage":"Object is not a ByteRate","messagePattern":"Object is not a ByteRate","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/Bytes/ByteRate.cs","lineNumber":170,"sourceCode":"\n    /// <inheritdoc />\n    /// <remarks>\n    /// Equality requires the other instance to have the same runtime type.\n    /// </remarks>\n    public override bool Equals(object? obj) =>\n        obj?.GetType() == GetType() && Equals((ByteRate)obj);\n\n    /// <inheritdoc />\n    public override int GetHashCode() =>\n        BytesPerSecond.GetHashCode();\n\n    /// <inheritdoc />\n    public int CompareTo(object? obj) =>\n        obj switch\n        {\n            null => 1,\n            ByteRate other => CompareTo(other),\n            _ => throw new ArgumentException(\"Object is not a ByteRate\", nameof(obj)),\n        };\n\n    double BytesPerSecond => Size.Bytes / Interval.TotalSeconds;\n}","sourceCodeStart":152,"sourceCodeEnd":174,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/Bytes/ByteRate.cs#L152-L174","documentation":"Thrown by the non-generic ByteRate.CompareTo(object?) when the argument is not null and not a ByteRate instance. The method's pattern match handles null (returns 1) and ByteRate (delegates to the typed CompareTo); any other runtime type hits the default arm and throws ArgumentException with the message 'Object is not a ByteRate'. This implements the IComparable contract which requires type mismatch to throw ArgumentException.","triggerScenarios":"Calling byteRate.CompareTo(obj) where obj is an instance of a different type — e.g. a boxed int, a string, a ByteSize, or any other object. This can happen when ByteRate is stored in a non-generic collection or sorted via IComparable without a typed comparer.","commonSituations":"A developer places ByteRate instances in an ArrayList or sorts them through a non-generic API that calls CompareTo with boxed objects of mixed types. Or a comparison function receives values from an untyped source.","solutions":["Ensure the argument to CompareTo is a ByteRate instance or null before calling the non-generic overload.","Prefer the typed ByteRate.CompareTo(ByteRate) overload when both operands are known to be ByteRate.","If using a non-generic collection, switch to a generic List<ByteRate> to get type safety at compile time."],"exampleFix":"// before — non-generic CompareTo with wrong type\nvar cmp = byteRate.CompareTo(someByteSize); // ByteSize, not ByteRate\n\n// after — compare two ByteRate instances\nvar cmp = byteRate.CompareTo(otherByteRate);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool IsByteRate(object? obj) => obj is ByteRate;","tryCatchPattern":null,"preventionTips":["Prefer the typed ByteRate.CompareTo(ByteRate) overload over the non-generic CompareTo(object?).","Use generic collections (List<ByteRate>) instead of non-generic ones (ArrayList) to ensure type safety.","Type-check the argument before calling the non-generic CompareTo: if (obj is ByteRate other) { ... }"],"tags":["runtime","byte-rate","argument","iccomparable","type-mismatch"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}