{"record":{"id":"0a955a50b4bb9599","repo":"clockworklabs/SpacetimeDB","slug":"argument-must-be-a-identity","errorCode":null,"errorMessage":"Argument must be a Identity","messagePattern":"Argument must be a Identity","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/Builtins.cs","lineNumber":337,"sourceCode":"    }\n\n    // This must be explicitly implemented, otherwise record will generate a new implementation.\n    public override string ToString() => Util.ToHexBigEndian(value);\n\n    /// <inheritdoc cref=\"IComparable.CompareTo(object)\" />\n    public int CompareTo(object? value)\n    {\n        if (value is Identity 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 Identity\", nameof(value));\n        }\n    }\n\n    /// <inheritdoc cref=\"IComparable{T}.CompareTo(T)\" />\n    public int CompareTo(Identity identity) => this.value.CompareTo(identity.value);\n}\n\n/// <summary>\n/// A timestamp that represents a unique moment in time (in the Earth's reference frame).\n///\n/// This type may be converted to/from a DateTimeOffset, but the conversion can lose precision.\n/// This type has less precision than DateTimeOffset (units of microseconds rather than units of 100ns).\n/// </summary>\n[StructLayout(LayoutKind.Sequential)] // we should be able to use it in FFI\npublic record struct Timestamp(long MicrosecondsSinceUnixEpoch)\n    : IStructuralReadWrite,\n        IComparable<Timestamp>\n{","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-csharp/BSATN.Runtime/Builtins.cs#L319-L355","documentation":"Identity is the client's 256-bit user/module identity type. Its untyped IComparable.CompareTo(object?) overload accepts only another Identity or null (null sorts after); any other runtime type throws ArgumentException.","triggerScenarios":"Calling CompareTo(object?) with a boxed ConnectionId, string, U256, or other non-Identity value — via object-based sorting or comparison of identity collections.","commonSituations":"Ordering mixed subscriber/identity records; comparing ids deserialized as object from JSON; generic helpers that take IComparable with object arguments.","solutions":["Use the typed CompareTo(Identity) overload","Pattern-match (if (o is Identity id)) before comparing boxed values","Keep identity collections typed as Identity[]"],"exampleFix":"// before\nint cmp = identity.CompareTo(otherObject); // ArgumentException: Argument must be a Identity\n\n// after\nif (otherObject is Identity other)\n{\n    int cmp = identity.CompareTo(other);\n}","handlingStrategy":"type-guard","validationCode":"static bool CanCompareWithIdentity(object? other) => other is null || other is Identity;","typeGuard":"static bool IsIdentity(object? value) => value is Identity;","tryCatchPattern":"try\n{\n    var cmp = ((IComparable)identity).CompareTo(boxed);\n}\ncatch (ArgumentException)\n{\n    // convert to Identity or reject the mixed comparison\n}","preventionTips":["Use the typed CompareTo(Identity)","Keep identity collections typed","Pattern-match boxed ids before comparing"],"tags":["csharp","spacetimedb","identity","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"}