clockworklabs/SpacetimeDB · error · ArgumentException
Argument must be a I256
Error message
Argument must be a I256
What it means
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.
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
Example fix
// before object x = someI128; int cmp = i256.CompareTo(x); // ArgumentException: Argument must be a I256 // after int cmp = i256.CompareTo((I256)x); // only after verifying/casting the type
Defensive patterns
Strategy: type-guard
Validate before calling
static bool CanCompareWithI256(object? other) => other is null || other is SpacetimeDB.I256;
Type guard
static bool IsI256(object? value) => value is SpacetimeDB.I256;
Try / catch
try
{
var cmp = ((IComparable)i256Value).CompareTo(boxed);
}
catch (ArgumentException)
{
// convert operand to I256 or reject the mixed comparison
} Prevention
- Use CompareTo(I256) or comparison operators
- Store 256-bit values in typed arrays
- Validate boxed operand types before object-based comparisons
When it happens
Trigger: 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.
Common situations: Comparing Identity-sized values pulled out of object-typed collections; mixed numeric sorts; ported code that previously compared BigInteger with other numerics.
Related errors
- Argument must be a I128
- Argument must be a U128
- Argument must be a U256
- Argument must be a ConnectionId
- Argument must be a Identity
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/ba253d7136b0976d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/bindings-csharp/BSATN.Runtime/BSATN/I256.cs:50
internal U128 Lower => _lower;
internal U128 Upper => _upper;
/// <inheritdoc cref="IComparable.CompareTo(object)" />
public int CompareTo(object? value)
{
if (value is I256 other)
{
return CompareTo(other);
}
else if (value is null)
{
return 1;
}
else
{
throw new ArgumentException("Argument must be a I256", nameof(value));
}
}
/// <inheritdoc cref="IComparable{T}.CompareTo(T)" />
public int CompareTo(I256 value)
{
if (this < value)
{
return -1;
}
else if (this > value)
{
return 1;
}
else
{
return 0;
}View on GitHub (pinned to 6dee26c6ef)