{"record":{"id":"28dc8aee62912ccd","repo":"clockworklabs/SpacetimeDB","slug":"argument-must-be-a-connectionid","errorCode":null,"errorMessage":"Argument must be a ConnectionId","messagePattern":"Argument must be a ConnectionId","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/Builtins.cs","lineNumber":233,"sourceCode":"        // --- / customized ---\n    }\n\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 ConnectionId 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 ConnectionId\", nameof(value));\n        }\n    }\n\n    /// <inheritdoc cref=\"IComparable{T}.CompareTo(T)\" />\n    public int CompareTo(ConnectionId connectionId) => this.value.CompareTo(connectionId.value);\n}\n\n[StructLayout(LayoutKind.Sequential)]\npublic readonly record struct Identity : IEquatable<Identity>, IComparable, IComparable<Identity>\n{\n    private readonly U256 value;\n\n    internal Identity(U256 val) => value = val;\n\n    /// <summary>\n    /// Create an Identity from a LITTLE-ENDIAN byte array.\n    ///\n    /// If you are parsing an Identity from a string, you probably want FromHexString instead,","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-csharp/BSATN.Runtime/Builtins.cs#L215-L251","documentation":"The non-generic IComparable.CompareTo(object) on ConnectionId throws ArgumentException when the argument is neither a ConnectionId nor null (null sorts as greater, returning 1). This is the standard BCL pattern: object-based comparison refuses types it cannot meaningfully order.","triggerScenarios":"((IComparable)connId).CompareTo(otherBoxed); sorting or binary-searching non-generic collections (ArrayList, object[]) that contain ConnectionIds plus other values; generic-free comparison helpers passing object.","commonSituations":"Bridging into non-generic APIs (older reflection-based serializers, DataTable keys, COM interop); dedup/sort utilities written against object.","solutions":["Compare with the typed overload connId.CompareTo(otherConnectionId)","Store ConnectionIds in strongly-typed collections (List<ConnectionId>, Dictionary<ConnectionId, ...>)","Narrow first: if (obj is ConnectionId cid) ... else throw/handle","For mixed-key maps, use the hex string form as the common comparable key"],"exampleFix":"// before\nlist.Sort((a, b) => ((IComparable)a).CompareTo(b)); // mixed types throw\n\n// after\nlist.Sort((a, b) => (a, b) switch { (ConnectionId x, ConnectionId y) => x.CompareTo(y), _ => throw new ArgumentException(\"Mixed key types\") });","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool IsConnectionId(object? o) => o is ConnectionId;","tryCatchPattern":null,"preventionTips":["Use List<ConnectionId>/Dictionary<ConnectionId,...> instead of object-based collections","Call the typed CompareTo(ConnectionId) overload","Type-test before invoking non-generic comparison APIs"],"tags":["csharp","connection-id","icomparable","type-mismatch","spacetimedb"],"backgroundTag":"invalid-argument-type","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}