{"record":{"id":"6f8a42340debf889","repo":"dotnet/efcore","slug":"could-not-found-symbol-for-parameter-lambda-para","errorCode":null,"errorMessage":"Could not found symbol for parameter lambda: {parameter}","messagePattern":"Could not found symbol for parameter lambda: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":1059,"sourceCode":"        {\n            throw new NotSupportedException(\"Async lambdas are not supported\");\n        }\n\n        var lambdaParameters = lambda switch\n        {\n            SimpleLambdaExpressionSyntax simpleLambda => SyntaxFactory.SingletonSeparatedList(simpleLambda.Parameter),\n            ParenthesizedLambdaExpressionSyntax parenthesizedLambda => parenthesizedLambda.ParameterList.Parameters,\n\n            _ => throw new UnreachableException()\n        };\n\n        var translatedParameters = new List<ParameterExpression>();\n        foreach (var parameter in lambdaParameters)\n        {\n            if (_semanticModel.GetDeclaredSymbol(parameter) is not { } parameterSymbol\n                || ResolveType(parameterSymbol.Type) is not { } parameterType)\n            {\n                throw new InvalidOperationException(\"Could not found symbol for parameter lambda: \" + parameter);\n            }\n\n            translatedParameters.Add(Parameter(parameterType, parameter.Identifier.Text));\n        }\n\n        _parameterStack.Push(\n            _parameterStack.Peek()\n                .AddRange(\n                    translatedParameters.Select(p\n                        => new KeyValuePair<string, ParameterExpression>(p.Name ?? throw new NotImplementedException(), p))));\n\n        try\n        {\n            var body = Visit(lambda.ExpressionBody);\n\n            return expectedType switch\n            {\n                // If there's no contextual expected type, we allow the lambda's type to be inferred from its parameters and the body's","sourceCodeStart":1041,"sourceCodeEnd":1077,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L1041-L1077","documentation":"Thrown by CSharpToLinqTranslator when iterating lambda parameters: either SemanticModel.GetDeclaredSymbol(parameter) returned null (Roslyn could not bind the parameter symbol) or ResolveType(parameterSymbol.Type) returned null (the parameter's type could not be mapped to a CLR Type). The translator cannot build a ParameterExpression without a resolvable symbol and type.","triggerScenarios":"A query lambda has a parameter whose type comes from an assembly not referenced in the Roslyn Compilation passed to Load(compilation, dbContext, additionalAssembly), or whose type is an unsafe/pointer type, a tuple with named elements that fail symbol resolution, or a type from an AssemblyLoadContext that has been unloaded.","commonSituations":"Building a source generator / precompiled-query host where the project references are not all surfaced to the Compilation; using types defined in a separate test assembly loaded only into a collectible AssemblyLoadContext without passing it as additionalAssembly; a broken Compilation that has upstream diagnostics.","solutions":["Pass the missing assembly via the additionalAssembly parameter of CSharpToLinqTranslator.Load(...) so ResolveType can find it.","Ensure the Roslyn Compilation used in Load(...) includes MetadataReferences for every assembly the query lambda's parameter types come from.","Rebuild/reload the Compilation if its AssemblyLoadContext was unloaded (typical in tests); avoid collectible ALCs for the compiled query host.","Avoid unsafe/pointer or otherwise exotic parameter types in EF query lambdas."],"exampleFix":"// before\ntranslator.Load(compilation, dbContext);\nvar expr = translator.Translate(lambdaNode, semanticModel);\n\n// after\ntranslator.Load(compilation, dbContext, additionalAssembly: typeof(ParameterType).Assembly);\nvar expr = translator.Translate(lambdaNode, semanticModel);","handlingStrategy":"validation","validationCode":"// Pre-check that every lambda parameter resolves to a symbol and a CLR type.\n// (Requires the SemanticModel and the translator's assembly-loading setup.)\nusing Microsoft.CodeAnalysis;\n\nbool ParametersResolvable(\n    Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousFunctionExpressionSyntax lambda,\n    SemanticModel model,\n    System.Reflection.Assembly? additionalAssembly)\n{\n    var parameters = lambda switch\n    {\n        Microsoft.CodeAnalysis.CSharp.Syntax.SimpleLambdaExpressionSyntax s\n            => new[] { s.Parameter },\n        Microsoft.CodeAnalysis.CSharp.Syntax.ParenthesizedLambdaExpressionSyntax p\n            => p.ParameterList.Parameters.ToArray(),\n        _ => Array.Empty<Microsoft.CodeAnalysis.CSharp.Syntax.ParameterSyntax>()\n    };\n\n    foreach (var p in parameters)\n    {\n        if (model.GetDeclaredSymbol(p) is not IParameterSymbol ps) return false;\n        var t = ps.Type?.ToDisplayString();\n        if (t is null) return false;\n        if (Type.GetType(t) is null\n            && (additionalAssembly?.GetType(t) is null)) return false;\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    return translator.Translate(lambdaNode, semanticModel);\n}\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Could not found symbol for parameter lambda\"))\n{\n    // Re-throw with actionable context: which parameter, which assembly is missing.\n    throw new InvalidOperationException(\n        $\"Failed to resolve a lambda parameter type. \" +\n        $\"Pass the containing assembly via CSharpToLinqTranslator.Load(compilation, ctx, additionalAssembly). \" +\n        $\"Original: {ex.Message}\", ex);\n}","preventionTips":["Pass additionalAssembly whenever the query references types defined outside the main Compilation.","Keep the AssemblyLoadContext that holds user code alive for the duration of precompiled-query translation.","Treat any C# compile error in the project as a hard blocker before invoking the translator."],"tags":["ef-core","query-translation","roslyn","semantic-model","assembly-loading","precompiled-queries"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}