{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L1102-L1138","documentation":"Thrown by ResolveType(SyntaxNode) when _semanticModel.GetTypeInfo(node).Type is null - Roslyn cannot determine the type of the syntax node. This is a semantic-analysis failure: the node has no resolvable type symbol. Part of EF Core's precompiled-query C#-to-LINQ translation.","triggerScenarios":"Any syntax node whose type info is unresolved: dynamic usage, error types from syntax errors, unresolvable generic constraints, or types from unreferenced assemblies.","commonSituations":"Missing project/assembly references; 'dynamic' usage in translated query code; syntax errors in the source causing Roslyn to emit error types; incremental compilation staleness.","solutions":["Add the missing assembly reference that defines the type.","Fix any compile errors in the source (Roslyn returns null type info for error-laden nodes).","Avoid 'dynamic' in code intended for C#-to-LINQ translation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify Roslyn can resolve a type for every node you will translate\nforeach (var node in nodesToTranslate)\n{\n    if (semanticModel.GetTypeInfo(node).Type is null)\n        throw new InvalidOperationException(\n            $\"Cannot resolve type for node '{node}' - check references and source errors.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the source compiles cleanly before translation (errors produce null type info).","Avoid 'dynamic' in translatable query code.","Include all project references in the Compilation."],"tags":["efcore","roslyn","semantic-model","type-resolution","references"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}