{"record":{"id":"da15f801c8b9e5e9","repo":"clockworklabs/SpacetimeDB","slug":"could-not-resolve-type-type","errorCode":null,"errorMessage":"Could not resolve type {type}","messagePattern":"Could not resolve type (.+?)","errorType":"exception","errorClass":"UnresolvedTypeException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/BSATN.Codegen/Utils.cs","lineNumber":153,"sourceCode":"                SpecialType.System_Double => \"SpacetimeDB.BSATN.F64\",\n                SpecialType.System_String => \"SpacetimeDB.BSATN.String\",\n                SpecialType.None => GetTypeInfoForNamedType(namedType),\n                _ => throw new InvalidOperationException(\n                    $\"Unsupported special type {type} ({type.SpecialType})\"\n                ),\n            },\n            IArrayTypeSymbol { ElementType: var elementType } => elementType.SpecialType\n            == SpecialType.System_Byte\n                ? \"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\",","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-csharp/BSATN.Codegen/Utils.cs#L135-L171","documentation":"When GetTypeInfoForNamedType encounters a symbol with TypeKind.Error — the placeholder Roslyn creates when a type reference does not resolve — it throws UnresolvedTypeException (an InvalidOperationException subclass) whose message is 'Could not resolve type {type}'. In other words: the generator ran on code containing a broken type reference (typo, missing using, missing assembly/project reference) and reports it instead of generating nonsense.","triggerScenarios":"A type referenced from a table, reducer, or [SpacetimeDB.Type] type fails to compile-resolve: missing using/global using, missing ProjectReference or PackageReference to the assembly declaring it, a typo in the type name, or a type defined inside another source generator's output that this generator cannot see.","commonSituations":"Schema types split across projects without referencing the model project; CI builds where NuGet restore silently skipped the SDK; a refactor renamed a type but the schema file still uses the old name; implicit-usings disabled in one project but enabled in another.","solutions":["Add the missing using directive (or fully qualify the type) in the file that declares the table/reducer","Add the missing ProjectReference/PackageReference for the assembly that declares the type","Fix the typo — the message prints the exact symbol name the compiler saw","Run dotnet restore then rebuild to rule out a stale restore"],"exampleFix":"// before\nnamespace Game.Schema {\n    [SpacetimeDB.Table(Public = true)]\n    public partial struct Guild {\n        public GuildSettings Settings; // GuildSettings unresolved\n    }\n}\n\n// after\nusing Game.Model; // namespace that actually declares GuildSettings\n// (or add: <ProjectReference Include=\"..\\Game.Model\\Game.Model.csproj\" />)\nnamespace Game.Schema {\n    [SpacetimeDB.Table(Public = true)]\n    public partial struct Guild {\n        public GuildSettings Settings;\n    }\n}","handlingStrategy":"validation","validationCode":"// The generator surfaces unresolved references at build time.\n// Pre-validate that every schema-reachable type compiles:\n//   dotnet build src/Schema -warnaserror\n// The message prints the unresolved symbol name — search for it and add the\n// missing using / ProjectReference / PackageReference.","typeGuard":null,"tryCatchPattern":"// compile-time error: nothing to catch. Resolve the reference and rebuild.","preventionTips":["Keep schema types in one assembly that references everything they use","Enable implicit usings consistently across projects","Run dotnet restore in CI before build so missing packages fail loudly"],"tags":["csharp","source-generator","roslyn","missing-reference"],"backgroundTag":"unresolved-type-reference","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"}