{"record":{"id":"a0f357c2f3f9756f","repo":"clockworklabs/SpacetimeDB","slug":"randombytes-must-be-exactly-4-bytes","errorCode":null,"errorMessage":"randomBytes must be exactly 4 bytes","messagePattern":"randomBytes must be exactly 4 bytes","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs","lineNumber":127,"sourceCode":"    /// </param>\n    /// <exception cref=\"InvalidOperationException\">\n    /// Thrown if the counter value is negative.\n    /// </exception>\n    /// <exception cref=\"ArgumentException\">\n    /// Thrown if <paramref name=\"randomBytes\"/> is not exactly 4 bytes long, or <paramref name=\"now\"/> is  before unix epoch.\n    /// </exception>\n    /// <returns>\n    /// A <see cref=\"Uuid\"/> `v7`.\n    /// </returns>\n    public static Uuid FromCounterV7(\n        ref int counter,\n        Timestamp now,\n        ReadOnlySpan<byte> randomBytes // must be length 4\n    )\n    {\n        if (randomBytes.Length != 4)\n        {\n            throw new ArgumentException(\"randomBytes must be exactly 4 bytes\", nameof(randomBytes));\n        }\n\n        if (counter < 0)\n        {\n            throw new InvalidOperationException(\"uuid counter must be non-negative\");\n        }\n\n        if (now.MicrosecondsSinceUnixEpoch < 0)\n        {\n            throw new ArgumentException(\"timestamp before unix epoch\", nameof(now));\n        }\n        var unixTsMs = now.MicrosecondsSinceUnixEpoch / 1_000;\n\n        // monotonic 31-bit\n        var counterVal = counter;\n        counter = (counter + 1) & 0x7FFF_FFFF;\n\n        Span<byte> bytes = stackalloc byte[16];","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs#L109-L145","documentation":"Error \"randomBytes must be exactly 4 bytes\" thrown in clockworklabs/SpacetimeDB.","triggerScenarios":"Thrown at crates/bindings-csharp/BSATN.Runtime/BSATN/Uuid.cs:127 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}