{"record":{"id":"ba253d7136b0976d","repo":"clockworklabs/SpacetimeDB","slug":"argument-must-be-a-i256","errorCode":null,"errorMessage":"Argument must be a I256","messagePattern":"Argument must be a I256","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/BSATN/I256.cs","lineNumber":50,"sourceCode":"\n    internal U128 Lower => _lower;\n\n    internal U128 Upper => _upper;\n\n    /// <inheritdoc cref=\"IComparable.CompareTo(object)\" />\n    public int CompareTo(object? value)\n    {\n        if (value is I256 other)\n        {\n            return CompareTo(other);\n        }\n        else if (value is null)\n        {\n            return 1;\n        }\n        else\n        {\n            throw new ArgumentException(\"Argument must be a I256\", nameof(value));\n        }\n    }\n\n    /// <inheritdoc cref=\"IComparable{T}.CompareTo(T)\" />\n    public int CompareTo(I256 value)\n    {\n        if (this < value)\n        {\n            return -1;\n        }\n        else if (this > value)\n        {\n            return 1;\n        }\n        else\n        {\n            return 0;\n        }","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-csharp/BSATN.Runtime/BSATN/I256.cs#L32-L68","documentation":"I256 is the SpacetimeDB BSATN.Runtime 256-bit signed integer type. Its untyped IComparable.CompareTo(object?) overload accepts only another I256 or null; any other runtime type throws ArgumentException because ordering across unrelated types is undefined.","triggerScenarios":"Calling CompareTo(object?) with a boxed value that is not an I256 — e.g. an I128, BigInteger, long, or string — via Array.Sort, ArrayList, or manual object comparisons.","commonSituations":"Comparing Identity-sized values pulled out of object-typed collections; mixed numeric sorts; ported code that previously compared BigInteger with other numerics.","solutions":["Call the typed CompareTo(I256) overload or use the comparison operators","Convert or pattern-match the other operand to I256 before comparing","Keep collections homogeneous (I256[]) or pass a custom comparer"],"exampleFix":"// before\nobject x = someI128;\nint cmp = i256.CompareTo(x); // ArgumentException: Argument must be a I256\n\n// after\nint cmp = i256.CompareTo((I256)x); // only after verifying/casting the type","handlingStrategy":"type-guard","validationCode":"static bool CanCompareWithI256(object? other) => other is null || other is SpacetimeDB.I256;","typeGuard":"static bool IsI256(object? value) => value is SpacetimeDB.I256;","tryCatchPattern":"try\n{\n    var cmp = ((IComparable)i256Value).CompareTo(boxed);\n}\ncatch (ArgumentException)\n{\n    // convert operand to I256 or reject the mixed comparison\n}","preventionTips":["Use CompareTo(I256) or comparison operators","Store 256-bit values in typed arrays","Validate boxed operand types before object-based comparisons"],"tags":["csharp","spacetimedb","bsatn","int256","icomparable"],"backgroundTag":"icomparable-type-mismatch","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}