{"record":{"id":"8bc02cc46ef77257","repo":"clockworklabs/SpacetimeDB","slug":"enum-type-does-not-have-a-spacetimedb-type-att","errorCode":null,"errorMessage":"Enum {type} does not have a [SpacetimeDB.Type] attribute","messagePattern":"Enum (.+?) does not have a \\[SpacetimeDB\\.Type\\] attribute","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Codegen/Utils.cs","lineNumber":162,"sourceCode":"                ? \"SpacetimeDB.BSATN.ByteArray\"\n                : $\"SpacetimeDB.BSATN.Array<{elementType}, {GetTypeInfo(elementType)}>\",\n            _ => throw new InvalidOperationException($\"Unsupported type {type}\"),\n        };\n\n        static string GetTypeInfoForNamedType(INamedTypeSymbol type)\n        {\n            if (type.TypeKind == Microsoft.CodeAnalysis.TypeKind.Error)\n            {\n                throw new UnresolvedTypeException(type);\n            }\n            if (type.TypeKind == Microsoft.CodeAnalysis.TypeKind.Enum)\n            {\n                if (\n                    !type.GetAttributes()\n                        .Any(a => a.AttributeClass?.ToString() == \"SpacetimeDB.TypeAttribute\")\n                )\n                {\n                    throw new InvalidOperationException(\n                        $\"Enum {type} does not have a [SpacetimeDB.Type] attribute\"\n                    );\n                }\n                return $\"SpacetimeDB.BSATN.Enum<{SymbolToName(type)}>\";\n            }\n            var result = type.OriginalDefinition.ToString() switch\n            {\n                // {U/I}{128/256} are not treated by C# as regular primitives, so we need to match them by type name.\n                \"System.Int128\" => \"SpacetimeDB.BSATN.I128\",\n                \"System.UInt128\" => \"SpacetimeDB.BSATN.U128\",\n                \"SpacetimeDB.I128\" => \"SpacetimeDB.BSATN.I128Stdb\",\n                \"SpacetimeDB.U128\" => \"SpacetimeDB.BSATN.U128Stdb\",\n                \"SpacetimeDB.I256\" => \"SpacetimeDB.BSATN.I256\",\n                \"SpacetimeDB.U256\" => \"SpacetimeDB.BSATN.U256\",\n                \"System.Collections.Generic.List<T>\" => $\"SpacetimeDB.BSATN.List\",\n                \"System.Collections.Generic.IEnumerable<T>\" => $\"SpacetimeDB.BSATN.List\",\n                // If we're here, then this is nullable *value* type like `int?`.\n                \"System.Nullable<T>\" => $\"SpacetimeDB.BSATN.ValueOption\",","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-csharp/BSATN.Codegen/Utils.cs#L144-L180","documentation":"When a named type is an enum, GetTypeInfoForNamedType requires the [SpacetimeDB.Type] attribute (checked by looking for SpacetimeDB.TypeAttribute) before emitting SpacetimeDB.BSATN.Enum<...>; without it, it throws InvalidOperationException. Enum membership in the module schema is deliberately explicit — the attribute is what makes the generator emit BSATN and client bindings for the enum.","triggerScenarios":"Declaring `enum Status { ... }` without [SpacetimeDB.Type] and then using it as a table column, reducer parameter, or member of another [SpacetimeDB.Type] type. Also triggers when the attribute is spelled differently or comes from another namespace.","commonSituations":"Assuming enums are picked up automatically the way [SpacetimeDB.Table] tables are; writing [Type] without `using SpacetimeDB;`; using a third-party enum you cannot annotate in a schema type.","solutions":["Add [SpacetimeDB.Type] to the enum declaration","Make sure the attribute resolves — add `using SpacetimeDB;` or fully qualify [SpacetimeDB.Type]","For third-party enums you cannot edit, store the underlying integer and convert at the edges","Rebuild after adding the attribute"],"exampleFix":"// before\npublic enum Status { Offline, Online }\n\n[SpacetimeDB.Table(Public = true)]\npublic partial struct Player {\n    public Status Status; // throws: no [SpacetimeDB.Type]\n}\n\n// after\nusing SpacetimeDB;\n\n[SpacetimeDB.Type]\npublic enum Status { Offline, Online }\n\n[SpacetimeDB.Table(Public = true)]\npublic partial struct Player {\n    public Status Status;\n}","handlingStrategy":"validation","validationCode":"// Convention check for schema projects (compile-time enforced by the generator):\n//   every enum used in tables/reducers carries [SpacetimeDB.Type]\n//   and `using SpacetimeDB;` is present in that file.","typeGuard":null,"tryCatchPattern":"// compile-time error: nothing to catch. Add the attribute and rebuild.","preventionTips":["Checklist: tables get [SpacetimeDB.Table]; enums and other row types get [SpacetimeDB.Type]","For third-party enums, store the underlying int in schema and map in code","Add a code-review rule that greps new enums for the attribute"],"tags":["csharp","source-generator","enum","attribute","schema"],"backgroundTag":"missing-schema-attribute","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"}