clockworklabs/SpacetimeDB · error · UnresolvedTypeException

Could not resolve type

Error message

Could not resolve type {type}

What it means

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.

Solutions

  1. Add the missing using directive (or fully qualify the type) in the file that declares the table/reducer
  2. Add the missing ProjectReference/PackageReference for the assembly that declares the type
  3. Fix the typo — the message prints the exact symbol name the compiler saw
  4. Run dotnet restore then rebuild to rule out a stale restore

Example fix

// before
namespace Game.Schema {
    [SpacetimeDB.Table(Public = true)]
    public partial struct Guild {
        public GuildSettings Settings; // GuildSettings unresolved
    }
}

// after
using Game.Model; // namespace that actually declares GuildSettings
// (or add: <ProjectReference Include="..\Game.Model\Game.Model.csproj" />)
namespace Game.Schema {
    [SpacetimeDB.Table(Public = true)]
    public partial struct Guild {
        public GuildSettings Settings;
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// The generator surfaces unresolved references at build time.
// Pre-validate that every schema-reachable type compiles:
//   dotnet build src/Schema -warnaserror
// The message prints the unresolved symbol name — search for it and add the
// missing using / ProjectReference / PackageReference.

Try / catch

// compile-time error: nothing to catch. Resolve the reference and rebuild.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/da15f801c8b9e5e9. Report an issue: GitHub.

Appendix: source

Thrown at crates/bindings-csharp/BSATN.Codegen/Utils.cs:153

                SpecialType.System_Double => "SpacetimeDB.BSATN.F64",
                SpecialType.System_String => "SpacetimeDB.BSATN.String",
                SpecialType.None => GetTypeInfoForNamedType(namedType),
                _ => throw new InvalidOperationException(
                    $"Unsupported special type {type} ({type.SpecialType})"
                ),
            },
            IArrayTypeSymbol { ElementType: var elementType } => elementType.SpecialType
            == SpecialType.System_Byte
                ? "SpacetimeDB.BSATN.ByteArray"
                : $"SpacetimeDB.BSATN.Array<{elementType}, {GetTypeInfo(elementType)}>",
            _ => throw new InvalidOperationException($"Unsupported type {type}"),
        };

        static string GetTypeInfoForNamedType(INamedTypeSymbol type)
        {
            if (type.TypeKind == Microsoft.CodeAnalysis.TypeKind.Error)
            {
                throw new UnresolvedTypeException(type);
            }
            if (type.TypeKind == Microsoft.CodeAnalysis.TypeKind.Enum)
            {
                if (
                    !type.GetAttributes()
                        .Any(a => a.AttributeClass?.ToString() == "SpacetimeDB.TypeAttribute")
                )
                {
                    throw new InvalidOperationException(
                        $"Enum {type} does not have a [SpacetimeDB.Type] attribute"
                    );
                }
                return $"SpacetimeDB.BSATN.Enum<{SymbolToName(type)}>";
            }
            var result = type.OriginalDefinition.ToString() switch
            {
                // {U/I}{128/256} are not treated by C# as regular primitives, so we need to match them by type name.
                "System.Int128" => "SpacetimeDB.BSATN.I128",

View on GitHub (pinned to 6dee26c6ef)