{"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/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs#L291-L327","documentation":"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.","triggerScenarios":"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.","commonSituations":"Sorting mixed identifier collections; generic comparison utilities that accept object; converting Uuid to Guid or string and comparing the boxed original.","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[]"],"exampleFix":"// before\nint cmp = uuid.CompareTo(boxedGuid); // ArgumentException: Argument must be a Uuid\n\n// after\nif (boxedGuid is Uuid other)\n{\n    int cmp = uuid.CompareTo(other);\n}","handlingStrategy":"type-guard","validationCode":"static bool CanCompareWithUuid(object? other) => other is null || other is SpacetimeDB.Uuid;","typeGuard":"static bool IsUuid(object? value) => value is SpacetimeDB.Uuid;","tryCatchPattern":"try\n{\n    var cmp = ((IComparable)uuidValue).CompareTo(boxed);\n}\ncatch (ArgumentException)\n{\n    // convert to Uuid (e.g. from Guid) or reject the mixed comparison\n}","preventionTips":["Use CompareTo(Uuid) or the comparison operators","Convert Guid to Uuid explicitly rather than comparing boxed values","Keep id collections typed as Uuid[]"],"tags":["csharp","spacetimedb","uuid","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"}