dotnet/efcore · error · InvalidOperationException
Could not find type symbol for
Error message
Could not find type symbol for: {node} What it means
Thrown by CSharpToLinqTranslator.ResolveType(SyntaxNode) when SemanticModel.GetTypeInfo(node).Type is null — Roslyn returned no ITypeSymbol for the node. The translator cannot translate a syntax node that has no resolvable type information into a LINQ expression.
Solutions
- Ensure the node passed to Translate/Visit is an expression node from a type-inferrable context, not a statement or declaration.
- Verify the SemanticModel came from the same SyntaxTree as the node (ReferenceEquals(semanticModel.SyntaxTree, node.SyntaxTree)).
- Resolve all C# compile errors in the source before translation — GetTypeInfo returns null when the tree has binding errors.
- If hosting the translator yourself, walk to the innermost expression node rather than passing a wrapping statement.
Example fix
// before var model = compilation.GetSemanticModel(otherTree); var e = translator.Translate(someNode, model); // after var tree = someNode.SyntaxTree; var model = compilation.GetSemanticModel(tree); var e = translator.Translate(someNode, model);
Defensive patterns
Strategy: validation
Validate before calling
// Verify the node is in a type-inferrable position and the model matches the tree.
using Microsoft.CodeAnalysis;
bool IsTranslatableExpressionNode(SyntaxNode node, SemanticModel model)
=> ReferenceEquals(model.SyntaxTree, node.SyntaxTree)
&& model.GetTypeInfo(node).Type is not null;
if (!IsTranslatableExpressionNode(node, semanticModel))
throw new InvalidOperationException("Node has no resolvable type; fix compile errors or pass an expression node from the same tree."); Prevention
- Always derive the SemanticModel from node.SyntaxTree before calling Translate.
- Ensure the source project compiles cleanly (no errors) before translation; GetTypeInfo returns null on binding failures.
- Walk to the innermost expression node rather than passing a wrapping statement/declaration node.
When it happens
Trigger: Visiting a syntax node that is not in a type-inferrable position (e.g. a statement or namespace node fed to Visit), or a Compilation with unresolved errors where type inference failed; or a node from a different SyntaxTree than the SemanticModel (mismatched tree/model).
Common situations: Driving CSharpToLinqTranslator with a node that is not an expression; passing a SemanticModel that does not match the node's SyntaxTree (the translator DebugAsserts this but a release build skips the assert); a Compilation produced from code with compile errors so GetTypeInfo returns null.
Related errors
- Could not found symbol for parameter lambda
- Couldn't find nested type
- Unknown generic type parameter symbol
- Couldn't resolve CLR type
- Lambda with modifiers not supported
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/6f0af036fde3471d.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:1120
/// <summary>
/// Given a Roslyn type symbol, returns a .NET reflection <see cref="Type" />.
/// </summary>
/// <param name="typeSymbol">The type symbol to be translated.</param>
/// <returns>A .NET reflection <see cref="Type" /> that corresponds to <paramref name="typeSymbol" />.</returns>
/// <remarks>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </remarks>
public virtual Type TranslateType(ITypeSymbol typeSymbol)
=> ResolveType(typeSymbol);
private Type ResolveType(SyntaxNode node)
=> _semanticModel.GetTypeInfo(node).Type is { } typeSymbol
? ResolveType(typeSymbol)
: throw new InvalidOperationException("Could not find type symbol for: " + node);
private Type ResolveType(ITypeSymbol typeSymbol, Dictionary<string, Type>? genericParameterMap = null)
{
switch (typeSymbol)
{
case INamedTypeSymbol { IsAnonymousType: true } anonymousTypeSymbol:
_anonymousTypeDefinitions ??= LoadAnonymousTypes(anonymousTypeSymbol.ContainingAssembly);
var properties = anonymousTypeSymbol.GetMembers().OfType<IPropertySymbol>().ToArray();
var found = _anonymousTypeDefinitions.TryGetValue(
properties.Select(p => p.Name).ToArray(),
out var anonymousTypeGenericDefinition);
Check.DebugAssert(found, "Anonymous type not found");
var constructorParameters = anonymousTypeGenericDefinition!.GetConstructors()[0].GetParameters();
var genericTypeArguments = new Type[constructorParameters.Length];
for (var i = 0; i < constructorParameters.Length; i++)
{View on GitHub (pinned to 3a2006ef56)