dotnet/efcore · error · InvalidOperationException
Could not found symbol for parameter lambda
Error message
Could not found symbol for parameter lambda: {parameter} What it means
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.
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.
Example fix
// before translator.Load(compilation, dbContext); var expr = translator.Translate(lambdaNode, semanticModel); // after translator.Load(compilation, dbContext, additionalAssembly: typeof(ParameterType).Assembly); var expr = translator.Translate(lambdaNode, semanticModel);
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check that every lambda parameter resolves to a symbol and a CLR type.
// (Requires the SemanticModel and the translator's assembly-loading setup.)
using Microsoft.CodeAnalysis;
bool ParametersResolvable(
Microsoft.CodeAnalysis.CSharp.Syntax.AnonymousFunctionExpressionSyntax lambda,
SemanticModel model,
System.Reflection.Assembly? additionalAssembly)
{
var parameters = lambda switch
{
Microsoft.CodeAnalysis.CSharp.Syntax.SimpleLambdaExpressionSyntax s
=> new[] { s.Parameter },
Microsoft.CodeAnalysis.CSharp.Syntax.ParenthesizedLambdaExpressionSyntax p
=> p.ParameterList.Parameters.ToArray(),
_ => Array.Empty<Microsoft.CodeAnalysis.CSharp.Syntax.ParameterSyntax>()
};
foreach (var p in parameters)
{
if (model.GetDeclaredSymbol(p) is not IParameterSymbol ps) return false;
var t = ps.Type?.ToDisplayString();
if (t is null) return false;
if (Type.GetType(t) is null
&& (additionalAssembly?.GetType(t) is null)) return false;
}
return true;
} Try / catch
try
{
return translator.Translate(lambdaNode, semanticModel);
}
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Could not found symbol for parameter lambda"))
{
// Re-throw with actionable context: which parameter, which assembly is missing.
throw new InvalidOperationException(
$"Failed to resolve a lambda parameter type. " +
$"Pass the containing assembly via CSharpToLinqTranslator.Load(compilation, ctx, additionalAssembly). " +
$"Original: {ex.Message}", ex);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not find type symbol for
- Could not load assembly for IAssemblySymbol
- Couldn't resolve CLR type
- Lambda with modifiers not supported
- Async lambdas are not supported
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/6f8a42340debf889.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:1059
{
throw new NotSupportedException("Async lambdas are not supported");
}
var lambdaParameters = lambda switch
{
SimpleLambdaExpressionSyntax simpleLambda => SyntaxFactory.SingletonSeparatedList(simpleLambda.Parameter),
ParenthesizedLambdaExpressionSyntax parenthesizedLambda => parenthesizedLambda.ParameterList.Parameters,
_ => throw new UnreachableException()
};
var translatedParameters = new List<ParameterExpression>();
foreach (var parameter in lambdaParameters)
{
if (_semanticModel.GetDeclaredSymbol(parameter) is not { } parameterSymbol
|| ResolveType(parameterSymbol.Type) is not { } parameterType)
{
throw new InvalidOperationException("Could not found symbol for parameter lambda: " + parameter);
}
translatedParameters.Add(Parameter(parameterType, parameter.Identifier.Text));
}
_parameterStack.Push(
_parameterStack.Peek()
.AddRange(
translatedParameters.Select(p
=> new KeyValuePair<string, ParameterExpression>(p.Name ?? throw new NotImplementedException(), p))));
try
{
var body = Visit(lambda.ExpressionBody);
return expectedType switch
{
// If there's no contextual expected type, we allow the lambda's type to be inferred from its parameters and the body'sView on GitHub (pinned to 3a2006ef56)