dotnet/efcore · error · InvalidOperationException
Couldn't find type symbol for: {type}
Error message
Couldn't find type symbol for: {type} What it means
Thrown in PrecompiledQueryCodeGenerator.GetTypeSymbol (line 1287) when a runtime System.Type's FullName cannot be resolved by compilation.GetTypeByMetadataName. After handling arrays and constructed generics, GetTypeSymbol falls back to looking the type up by its FullName in the analysis compilation; if that returns null it throws InvalidOperationException. The type is not visible to the Roslyn compilation performing code generation.
Source
Thrown at src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs:1287
return compilation.CreateArrayTypeSymbol(elementSymbol, type.GetArrayRank());
}
if (type.IsGenericType && !type.IsGenericTypeDefinition)
{
var genericDefinition = (INamedTypeSymbol)GetTypeSymbol(
compilation,
type.GetGenericTypeDefinition());
var typeArguments = type
.GetGenericArguments()
.Select(t => GetTypeSymbol(compilation, t))
.ToArray();
return genericDefinition.Construct(typeArguments);
}
return type.FullName is null || compilation.GetTypeByMetadataName(type.FullName) is not { } typeSymbol
? throw new InvalidOperationException($"Couldn't find type symbol for: {type}")
: typeSymbol;
}
[return: NotNullIfNotNull(nameof(name))]
private static string? SanitizeIdentifierName(string? name)
{
if (name == null)
{
return null;
}
if (string.IsNullOrWhiteSpace(name))
{
return "_";
}
var result = new string(
[.. name.Select(c => SyntaxFacts.IsIdentifierPartCharacter(c) ? c : '_')]);View on GitHub (pinned to dbf9771522)
Solutions
- Add the missing assembly reference to the project so the type is visible to the analysis compilation.
- Ensure any source-generated types are generated before precompiled-query analysis runs (check generator ordering / build target).
- Replace the unresolvable type with a concrete, named type defined in a referenced assembly.
- Clean and rebuild to refresh the analyzer's view of referenced assemblies.
Defensive patterns
Strategy: validation
Validate before calling
// Confirm the type is resolvable in the compilation before generating
if (type.FullName is null || compilation.GetTypeByMetadataName(type.FullName) is null)
{ /* add missing reference or exclude query */ } Try / catch
try { /* generate */ }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Couldn't find type symbol"))
{ /* add the missing assembly reference, then retry */ } Prevention
- Keep the analyzed project's assembly references complete.
- Ensure source-generated types exist before analysis runs.
- Use concrete, named types from referenced assemblies in precompiled queries.
When it happens
Trigger: Precompiling a query that references a type (entity, value, or parameter type) whose assembly is not referenced by the Roslyn Compilation, or whose FullName is null (e.g. an anonymous type used in an unsupported position, a nested type with an unspeakable name, or a type from an unloaded assembly). GetTypeSymbol returns null from GetTypeByMetadataName and throws.
Common situations: The project being analyzed is missing a reference to the assembly that defines a type used in the query. The type lives in a source-generated assembly not yet produced when the analyzer runs. A type with no resolvable FullName (anonymous/unspeakable) reaches type-symbol resolution. Stale/incremental analysis that hasn't loaded all references.
Related errors
- Could not find type symbol for: {fullyQualifiedMetadataName}
- Could not find type symbol for: {fullyQualifiedMetadataName}
- Couldn't find method symbol for: {memberAccessSyntax}
- Couldn't get interceptable location for: '{node}'.
- Could not resolve type symbol for: {parameter.Type}
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/a01cca4762068d85.
Report an issue: GitHub.