{"record":{"id":"b0595cab65a8da78","repo":"clockworklabs/SpacetimeDB","slug":"value-value-is-out-of-range-for-enum-typeof-t","errorCode":null,"errorMessage":"Value {value} is out of range for enum {typeof(T).Name}","messagePattern":"Value (.+?) is out of range for enum (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs","lineNumber":172,"sourceCode":"        // This was quite expensive because:\n        //   1. It uses reflection\n        //   2. It allocates\n        //   3. It is called on each row when decoding\n        //\n        // However, enum values are guaranteed to be sequential and zero based.\n        // Hence we only ever need to do an upper bound check.\n        // See `SpacetimeDB.Type.ParseEnum` for the syntax analysis.\n        //\n        // Note: this actually still uses reflection and allocates.\n        // It's hard to figure out how to avoid this without custom-generating a writer for each enum type.\n        var tag = Convert.ToByte(value);\n        if (tag < TagToValue.Length)\n        {\n            writer.Write(tag);\n        }\n        else\n        {\n            throw new ArgumentOutOfRangeException(\n                $\"Value {value} is out of range for enum {typeof(T).Name}\"\n            );\n        }\n    }\n\n    public AlgebraicType GetAlgebraicType(ITypeRegistrar registrar) =>\n        registrar.RegisterType<T>(\n            (_) =>\n                new AlgebraicType.Sum(\n#pragma warning disable CA2263 // netstandard2.1 lacks the generic Enum overloads.\n                    [\n                        .. Enum.GetNames(typeof(T))\n                            .Select(name => new AggregateElement(name, AlgebraicType.Unit)),\n                    ]\n#pragma warning restore CA2263\n                )\n        );\n}","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs#L154-L190","documentation":"Error \"Value {value} is out of range for enum {typeof(T).Name}\" thrown in clockworklabs/SpacetimeDB.","triggerScenarios":"Thrown at crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs:172 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"}