clockworklabs/SpacetimeDB · error · ArgumentException
Argument must be a Uuid
Error message
Argument must be a Uuid
What it means
Uuid is SpacetimeDB's 128-bit UUID type. Its untyped IComparable.CompareTo(object?) overload accepts only another Uuid or null (null sorts after); any other runtime type throws ArgumentException because ordering against unrelated types is undefined.
Solutions
- Use the typed CompareTo(Uuid) overload or the <, > operators
- Pattern-match the boxed value before comparing: if (o is Uuid u)
- Keep collections of ids typed as Uuid[] rather than object[]
Example fix
// before
int cmp = uuid.CompareTo(boxedGuid); // ArgumentException: Argument must be a Uuid
// after
if (boxedGuid is Uuid other)
{
int cmp = uuid.CompareTo(other);
} Defensive patterns
Strategy: type-guard
Validate before calling
static bool CanCompareWithUuid(object? other) => other is null || other is SpacetimeDB.Uuid;
Type guard
static bool IsUuid(object? value) => value is SpacetimeDB.Uuid;
Try / catch
try
{
var cmp = ((IComparable)uuidValue).CompareTo(boxed);
}
catch (ArgumentException)
{
// convert to Uuid (e.g. from Guid) or reject the mixed comparison
} Prevention
- Use CompareTo(Uuid) or the comparison operators
- Convert Guid to Uuid explicitly rather than comparing boxed values
- Keep id collections typed as Uuid[]
When it happens
Trigger: Calling CompareTo(object?) with a boxed Guid, string, U128, or other non-Uuid value — e.g. Array.Sort on object[] or comparing ids deserialized as object.
Common situations: Sorting mixed identifier collections; generic comparison utilities that accept object; converting Uuid to Guid or string and comparing the boxed original.
Related errors
- Argument must be a ConnectionId
- Argument must be a I128
- Argument must be a I256
- Argument must be a Identity
- Argument must be a U128
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/1dd77a551b4e9e2e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs:309
return ToGuid().ToString();
}
public readonly int CompareTo(Uuid other) => value.CompareTo(other.value);
/// <inheritdoc cref="IComparable.CompareTo(object)" />
public int CompareTo(object? value)
{
if (value is Uuid other)
{
return CompareTo(other);
}
else if (value is null)
{
return 1;
}
else
{
throw new ArgumentException("Argument must be a Uuid", nameof(value));
}
}
public static bool operator <(Uuid l, Uuid r) => l.CompareTo(r) < 0;
public static bool operator >(Uuid l, Uuid r) => l.CompareTo(r) > 0;
public readonly partial struct BSATN : IReadWrite<Uuid>
{
public Uuid Read(BinaryReader reader) => new(new SpacetimeDB.BSATN.U128Stdb().Read(reader));
public void Write(BinaryWriter writer, Uuid value) =>
new SpacetimeDB.BSATN.U128Stdb().Write(writer, value.value);
// --- / auto-generated ---
// --- customized ---
public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>View on GitHub (pinned to 6dee26c6ef)