{"record":{"id":"728c5ca850bc429b","repo":"louthy/language-ext","slug":"must-be-of-type-velocitysq","errorCode":null,"errorMessage":"must be of type VelocitySq","messagePattern":"must be of type VelocitySq","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Units of Measure/VelocitySq.cs","lineNumber":39,"sourceCode":"\n    public bool Equals(VelocitySq other) =>\n        Value.Equals(other.Value);\n\n    public bool Equals(VelocitySq other, double epsilon) =>\n        Math.Abs(other.Value - Value) < epsilon;\n\n    public override bool Equals(object? obj) =>\n        obj is VelocitySq sq && Equals(sq);\n\n    public override int GetHashCode() =>\n        Value.GetHashCode();\n\n    public int CompareTo(object? obj) =>\n        obj switch\n        {\n            null             => 1,\n            VelocitySq other => CompareTo(other),\n            _                => throw new ArgumentException($\"must be of type {nameof(VelocitySq)}\")\n        };\n\n    public int CompareTo(VelocitySq other) =>\n        Value.CompareTo(other.Value);\n\n    public VelocitySq Add(VelocitySq rhs) =>\n        new (Value + rhs.Value);\n\n    public VelocitySq Subtract(VelocitySq rhs) =>\n        new (Value - rhs.Value);\n\n    public VelocitySq Multiply(double rhs) =>\n        new (Value * rhs);\n\n    public VelocitySq Divide(double rhs) =>\n        new (Value / rhs);\n\n    public static VelocitySq operator *(VelocitySq lhs, double rhs) =>","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Units of Measure/VelocitySq.cs#L21-L57","documentation":"VelocitySq's explicit CompareTo(object?) throws ArgumentException('must be of type VelocitySq') for any non-null argument that is not a VelocitySq. This enforces the IComparable non-generic contract that comparing across types is an error rather than returning an arbitrary ordering. It can only trigger via object-typed compare paths, since the generic overload is type-safe.","triggerScenarios":"Invoking CompareTo((object)someNonVelocitySq) or sorting/searching non-generic collections (ArrayList, object arrays) that contain a VelocitySq among values of other types.","commonSituations":"Untyped legacy collections mixing unit-of-measure structs; dynamic/reflection comparisons; data-binding frameworks that box values before comparing.","solutions":["Keep collections and comparers generic (IComparer<VelocitySq>, List<VelocitySq>.Sort)","Pre-check the argument with `is VelocitySq` before non-generic comparison","Normalize incoming data to VelocitySq at ingestion time","Catch ArgumentException around any remaining object-typed compare paths"],"exampleFix":"// before\nint r = ((IComparable)vs).CompareTo(new Velocity(5)); // ArgumentException\n// after\nint r = other is VelocitySq o ? vs.CompareTo(o) : throw new ArgumentException(\"not a VelocitySq\");","handlingStrategy":"type-guard","validationCode":"if (obj is not VelocitySq) throw new ArgumentException(\"expected VelocitySq\");","typeGuard":"static bool IsVelocitySq(object? o) => o is VelocitySq;","tryCatchPattern":"try { r = ((IComparable)velSq).CompareTo(obj); }\ncatch (ArgumentException ex) { throw new InvalidOperationException(\"cross-type compare\", ex); }","preventionTips":["Keep VelocitySq in generic, typed containers","Never route unit structs through IComparable(object) when generics are available","Type-check before sorting untyped data","Normalize external values into VelocitySq before comparison"],"tags":["csharp","languageext","icomparable","argument"],"backgroundTag":"type-mismatch","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}