dotnet/efcore · critical · InvalidOperationException
Could not find type symbol for: {fullyQualifiedMetadataName}
Error message
Could not find type symbol for: {fullyQualifiedMetadataName} What it means
Thrown in PrecompiledQueryCodeGenerator.Symbols.GetTypeSymbolOrThrow (line 1362) during one-time symbol loading. The Symbols struct looks up a fixed set of core framework types (IEnumerable`1, IAsyncEnumerable`1, IEnumerator`1, IQueryable`1, IOrderedQueryable`1, IIncludableQueryable`2, Task`1); if any is missing from the compilation it throws. This means the Roslyn Compilation lacks the fundamental framework references needed to generate interceptor code at all.
Source
Thrown at src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs:1362
GetTypeSymbolOrThrow("System.Collections.Generic.IAsyncEnumerable`1");
GenericEnumerator =
GetTypeSymbolOrThrow("System.Collections.Generic.IEnumerator`1");
IQueryable =
GetTypeSymbolOrThrow("System.Linq.IQueryable`1");
IOrderedQueryable =
GetTypeSymbolOrThrow("System.Linq.IOrderedQueryable`1");
IIncludableQueryable =
GetTypeSymbolOrThrow("Microsoft.EntityFrameworkCore.Query.IIncludableQueryable`2");
GenericTask =
GetTypeSymbolOrThrow("System.Threading.Tasks.Task`1");
}
public static Symbols Load(Compilation compilation)
=> new(compilation);
private INamedTypeSymbol GetTypeSymbolOrThrow(string fullyQualifiedMetadataName)
=> _compilation.GetTypeByMetadataName(fullyQualifiedMetadataName)
?? throw new InvalidOperationException("Could not find type symbol for: " + fullyQualifiedMetadataName);
}
}
View on GitHub (pinned to dbf9771522)
Solutions
- Add framework references so the compilation can resolve System.Linq, System.Threading.Tasks, and the EF Core assemblies (e.g. reference Microsoft.EntityFrameworkCore and a TargetFramework that includes System.Linq).
- Run the EF tools against a project whose TargetFramework and PackageReferences include EF Core and the BCL.
- Verify the analyzer/source-generator is invoked with the project's full reference set, not a stripped one.
- Clean/rebuild and confirm the project compiles standalone before running precompilation.
Example fix
<!-- before: project missing EF Core / framework references -->
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
</ItemGroup>
<!-- after: include relational/design-time packages and a framework that provides System.Linq -->
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup> Defensive patterns
Strategy: validation
Validate before calling
// Verify the compilation can resolve the core symbols before Symbols.Load
string[] required = {
"System.Linq.IQueryable`1","System.Threading.Tasks.Task`1",
"Microsoft.EntityFrameworkCore.Query.IIncludableQueryable`2"
};
var missing = required.Where(n => compilation.GetTypeByMetadataName(n) is null).ToList();
if (missing.Count != 0) { /* add framework/EF references */ } Try / catch
try { Symbols.Load(compilation); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Could not find type symbol"))
{ /* fix references so System.Linq / EF Core are visible, then retry */ } Prevention
- Target a framework and reference set that includes System.Linq and EF Core.
- Run precompilation only against projects that reference EF Core.
- Restore packages and clean/rebuild before generating.
When it happens
Trigger: Symbols.Load is called on a Compilation that cannot resolve one of the hardcoded fully-qualified metadata names (e.g. System.Linq.IQueryable`1, System.Threading.Tasks.Task`1, Microsoft.EntityFrameworkCore.Query.IIncludableQueryable`2). GetTypeByMetadataName returns null and GetTypeSymbolOrThrow throws.
Common situations: Running precompiled-query generation against a project whose Compilation has no reference to System.Linq, the BCL facade assemblies, or the EF Core assembly (IIncludableQueryable). Misconfigured analyzer/source-generator host that strips framework references. A project type that does not reference the full framework (e.g. a minimal library without System.Linq).
Related errors
- Couldn't find type symbol for: {type}
- 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/daae912e71b2ca29.
Report an issue: GitHub.