{"record":{"id":"1dd77a551b4e9e2e","repo":"clockworklabs/SpacetimeDB","slug":"argument-must-be-a-uuid","errorCode":null,"errorMessage":"Argument must be a Uuid","messagePattern":"Argument must be a Uuid","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs","lineNumber":309,"sourceCode":"        return ToGuid().ToString();\n    }\n\n    public readonly int CompareTo(Uuid other) => value.CompareTo(other.value);\n\n    /// <inheritdoc cref=\"IComparable.CompareTo(object)\" />\n    public int CompareTo(object? value)\n    {\n        if (value is Uuid 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 Uuid\", nameof(value));\n        }\n    }\n\n    public static bool operator <(Uuid l, Uuid r) => l.CompareTo(r) < 0;\n\n    public static bool operator >(Uuid l, Uuid r) => l.CompareTo(r) > 0;\n\n    public readonly partial struct BSATN : IReadWrite<Uuid>\n    {\n        public Uuid Read(BinaryReader reader) => new(new SpacetimeDB.BSATN.U128Stdb().Read(reader));\n\n        public void Write(BinaryWriter writer, Uuid value) =>\n            new SpacetimeDB.BSATN.U128Stdb().Write(writer, value.value);\n\n        // --- / auto-generated ---\n\n        // --- customized ---\n        public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs#L291-L327","documentation":"The non-generic IComparable.CompareTo(object) implementation on Uuid throws ArgumentException for any argument that is neither a Uuid nor null (null compares as greater, returning 1). It exists to satisfy object-based comparison APIs and intentionally rejects other types instead of attempting a meaningless ordering.","triggerScenarios":"Invoking ((IComparable)uuid).CompareTo(someString); sorting/searching a mixed object[] or ArrayList containing Uuids and other types; passing a boxed value of another type through Comparer.Default or a non-generic BinarySearch/Sort key.","commonSituations":"Interfacing with old non-generic collections or serialization frameworks that call CompareTo(object); logging/dedup code that compares keys of heterogeneous provenance; copy-pasted comparison helpers typed as object.","solutions":["Use the strongly-typed overload: uuid.CompareTo(otherUuid), or the <, >, operators","Keep collections strongly typed (Uuid[], List<Uuid>) so the generic comparer is used","Type-check before comparing: if (obj is Uuid other) ... else handle mismatch explicitly","In mixed-type stores, compare on a normalized key (e.g., the 32-char hex string) instead of the raw object"],"exampleFix":"// before\nint c = ((IComparable)idA).CompareTo(boxedValue); // throws if not Uuid\n\n// after\nint c = boxedValue is Uuid other ? idA.CompareTo(other) : throw new ArgumentException($\"Cannot compare Uuid with {boxedValue?.GetType().Name}\", nameof(boxedValue));","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static int CompareSafe(Uuid left, object? right) =>\n    right switch\n    {\n        null => 1,\n        Uuid u => left.CompareTo(u),\n        _ => throw new ArgumentException($\"Cannot compare Uuid with {right.GetType().Name}\", nameof(right)),\n    };","tryCatchPattern":"try { result = ((IComparable)uuid).CompareTo(boxed); }\ncatch (ArgumentException) { /* heterogeneous data; fall back to comparing hex strings */ result = uuid.ToHexString().CompareTo(boxed?.ToString()); }","preventionTips":["Keep Uuid collections strongly typed (List<Uuid>, Uuid[]) so generic comparison is used","Prefer the typed CompareTo(Uuid) overload in all new code","Type-check before any object-typed comparison API"],"tags":["csharp","uuid","icomparable","type-mismatch"],"backgroundTag":"invalid-argument-type","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}