{"record":{"id":"c9e6e01c724b470d","repo":"clockworklabs/SpacetimeDB","slug":"argument-must-be-a-u256","errorCode":null,"errorMessage":"Argument must be a U256","messagePattern":"Argument must be a U256","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/BSATN/U256.cs","lineNumber":47,"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 U256 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 U256\", nameof(value));\n        }\n    }\n\n    /// <inheritdoc cref=\"IComparable{T}.CompareTo(T)\" />\n    public int CompareTo(U256 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":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-csharp/BSATN.Runtime/BSATN/U256.cs#L29-L65","documentation":"U256 is the SpacetimeDB BSATN.Runtime 256-bit unsigned integer. Its untyped CompareTo(object?) overload accepts only a U256 or null (null sorts after); any other runtime type throws ArgumentException.","triggerScenarios":"Comparing a U256 against a boxed value of another type (U128, long, string, Identity boxed differently) through the object-based IComparable path, e.g. Array.Sort on mixed object arrays.","commonSituations":"Ordering Identity-related values stored in object collections; generic comparison helpers that take object; ported code from BigInteger comparisons.","solutions":["Use the typed CompareTo(U256) overload or comparison operators","Convert the other operand to U256 explicitly before comparing","Provide an IComparer that handles type dispatch for heterogeneous data"],"exampleFix":"// before\nint cmp = u256.CompareTo(otherObject); // ArgumentException: Argument must be a U256\n\n// after\nint cmp = u256.CompareTo((U256)otherObject); // after verifying the runtime type","handlingStrategy":"type-guard","validationCode":"static bool CanCompareWithU256(object? other) => other is null || other is SpacetimeDB.U256;","typeGuard":"static bool IsU256(object? value) => value is SpacetimeDB.U256;","tryCatchPattern":"try\n{\n    var cmp = ((IComparable)u256Value).CompareTo(boxed);\n}\ncatch (ArgumentException)\n{\n    // convert operand to U256 or reject\n}","preventionTips":["Use CompareTo(U256) or operators","Store 256-bit ids in typed collections","Avoid comparing across integer widths without explicit conversion"],"tags":["csharp","spacetimedb","bsatn","uint256","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"}