{"record":{"id":"6f0af036fde3471d","repo":"dotnet/efcore","slug":"could-not-find-type-symbol-for-node","errorCode":null,"errorMessage":"Could not find type symbol for: {node}","messagePattern":"Could not find type symbol for: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":1120,"sourceCode":"\n    /// <summary>\n    ///     Given a Roslyn type symbol, returns a .NET reflection <see cref=\"Type\" />.\n    /// </summary>\n    /// <param name=\"typeSymbol\">The type symbol to be translated.</param>\n    /// <returns>A .NET reflection <see cref=\"Type\" /> that corresponds to <paramref name=\"typeSymbol\" />.</returns>\n    /// <remarks>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </remarks>\n    public virtual Type TranslateType(ITypeSymbol typeSymbol)\n        => ResolveType(typeSymbol);\n\n    private Type ResolveType(SyntaxNode node)\n        => _semanticModel.GetTypeInfo(node).Type is { } typeSymbol\n            ? ResolveType(typeSymbol)\n            : throw new InvalidOperationException(\"Could not find type symbol for: \" + node);\n\n    private Type ResolveType(ITypeSymbol typeSymbol, Dictionary<string, Type>? genericParameterMap = null)\n    {\n        switch (typeSymbol)\n        {\n            case INamedTypeSymbol { IsAnonymousType: true } anonymousTypeSymbol:\n                _anonymousTypeDefinitions ??= LoadAnonymousTypes(anonymousTypeSymbol.ContainingAssembly);\n                var properties = anonymousTypeSymbol.GetMembers().OfType<IPropertySymbol>().ToArray();\n                var found = _anonymousTypeDefinitions.TryGetValue(\n                    properties.Select(p => p.Name).ToArray(),\n                    out var anonymousTypeGenericDefinition);\n                Check.DebugAssert(found, \"Anonymous type not found\");\n\n                var constructorParameters = anonymousTypeGenericDefinition!.GetConstructors()[0].GetParameters();\n                var genericTypeArguments = new Type[constructorParameters.Length];\n\n                for (var i = 0; i < constructorParameters.Length; i++)\n                {","sourceCodeStart":1102,"sourceCodeEnd":1138,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L1102-L1138","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nvar model = compilation.GetSemanticModel(otherTree);\nvar e = translator.Translate(someNode, model);\n\n// after\nvar tree = someNode.SyntaxTree;\nvar model = compilation.GetSemanticModel(tree);\nvar e = translator.Translate(someNode, model);","handlingStrategy":"validation","validationCode":"// Verify the node is in a type-inferrable position and the model matches the tree.\nusing Microsoft.CodeAnalysis;\n\nbool IsTranslatableExpressionNode(SyntaxNode node, SemanticModel model)\n    => ReferenceEquals(model.SyntaxTree, node.SyntaxTree)\n       && model.GetTypeInfo(node).Type is not null;\n\nif (!IsTranslatableExpressionNode(node, semanticModel))\n    throw new InvalidOperationException(\"Node has no resolvable type; fix compile errors or pass an expression node from the same tree.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["ef-core","query-translation","roslyn","semantic-model","type-resolution"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}