{"record":{"id":"5ac017e12aec02ac","repo":"clockworklabs/SpacetimeDB","slug":"unknown-uuid-version","errorCode":null,"errorMessage":"Unknown UUID version","messagePattern":"Unknown UUID version","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs","lineNumber":218,"sourceCode":"    }\n\n    /// <summary>\n    /// Returns the <see cref=\"UuidVersion\"/> of this <see cref=\"Uuid\"/>.\n    ///\n    /// Throws <see cref=\"InvalidOperationException\"/> if the <see cref=\"Uuid\"/> version is unknown.\n    /// </summary>\n    public UuidVersion GetVersion()\n    {\n        var bytes = value.ToBytesBigEndian();\n        var version = (bytes[6] >> 4) & 0x0F;\n\n        return version switch\n        {\n            4 => UuidVersion.V4,\n            7 => UuidVersion.V7,\n            _ => this == Uuid.NIL ? UuidVersion.Nil\n            : this == Uuid.MAX ? UuidVersion.Max\n            : throw new InvalidOperationException(\"Unknown UUID version\"),\n        };\n    }\n\n    private static void GuidToBigEndianBytes(ReadOnlySpan<byte> guidBytes, Span<byte> be)\n    {\n        // Guid’s weird internal layout (mixed-endian)\n\n        // time_low (4 bytes) — little-endian → reverse\n        be[0] = guidBytes[3];\n        be[1] = guidBytes[2];\n        be[2] = guidBytes[1];\n        be[3] = guidBytes[0];\n\n        // time_mid (2 bytes) — little-endian\n        be[4] = guidBytes[5];\n        be[5] = guidBytes[4];\n\n        // time_hi_and_version (2 bytes) — little-endian","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs#L200-L236","documentation":"Uuid.GetVersion classifies a value as V4 or V7 from the version nibble (byte 6 high bits), with special cases for the all-zero NIL and all-ones MAX UUIDs. Any other version nibble (v1, v2, v3, v5, v6, v8) or a random 128-bit value throws InvalidOperationException, because the runtime only understands versions 4 and 7.","triggerScenarios":"Calling GetVersion on a Uuid constructed from a foreign UUID — a v1 time-based UUID from a legacy database, a namespaced v3/v5, or v6 from another library — or on an arbitrary 128-bit value that is not a UUID at all.","commonSituations":"Migrating identifiers from systems that emit non-v4/v7 UUIDs; debugging by parsing random 128-bit values as Uuid; third-party integrations with their own UUID generators.","solutions":["Generate UUIDs via the library's own constructors (FromRandomBytesV4, FromCounterV7) so the version is always 4 or 7","When ingesting foreign UUIDs, inspect the raw version nibble yourself and branch, instead of calling GetVersion","Validate inbound identifiers at the boundary and re-key non-v4/v7 values to library-generated ones"],"exampleFix":"// before\nvar u = Uuid.FromBigEndian(legacySystemBytes); // holds a v1 UUID\nvar v = u.GetVersion(); // InvalidOperationException: Unknown UUID version\n\n// after\nvar version = (legacySystemBytes[6] >> 4) & 0x0F;\nif (version is 4 or 7)\n{\n    var v = Uuid.FromBigEndian(legacySystemBytes).GetVersion();\n}\nelse\n{\n    // foreign UUID: re-key or handle explicitly\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static bool TryGetUuidVersion(Uuid u, out object? version)\n{\n    try { version = u.GetVersion(); return true; }\n    catch (InvalidOperationException) { version = null; return false; }\n}","tryCatchPattern":"try\n{\n    var v = u.GetVersion();\n}\ncatch (InvalidOperationException)\n{\n    // foreign UUID (v1/v3/v5/v6/...): re-key to a v4/v7 id or handle explicitly\n}","preventionTips":["Only feed library-generated (v4/v7) UUIDs into GetVersion","Check the raw version nibble when ingesting external UUIDs","Normalize foreign identifiers at the system boundary instead of downstream"],"tags":["csharp","spacetimedb","uuid","version"],"backgroundTag":"unsupported-uuid-version","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"}