dotnet/efcore · error · InvalidOperationException
Could not found symbol for parameter lambda: {parameter}
Error message
Could not found symbol for parameter lambda: {parameter} What it means
Thrown when _semanticModel.GetDeclaredSymbol(parameter) returns null OR ResolveType(parameterSymbol.Type) returns null for a lambda parameter. Roslyn's semantic model cannot resolve the parameter's symbol or its type. Note the typo ('found' instead of 'find') is in the source. Part of EF Core's precompiled-query C#-to-LINQ translation.
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 dbf9771522)
Solutions
- Ensure the SemanticModel is up to date and belongs to the same SyntaxTree as the node.
- Add missing assembly references to the Roslyn Compilation.
- Run a full rebuild to regenerate a consistent semantic model.
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the semantic model can resolve every lambda parameter symbol before translating
foreach (var param in root.DescendantNodes().OfType<ParameterSyntax>())
{
if (semanticModel.GetDeclaredSymbol(param) is null)
throw new InvalidOperationException(
$"Cannot resolve symbol for parameter '{param.Identifier}' - semantic model may be stale or references missing.");
} Prevention
- Build the Roslyn Compilation with all transitive assembly references present.
- Avoid translating syntax from a stale/incremental semantic model; force a full regeneration.
When it happens
Trigger: Translating a lambda where the Roslyn SemanticModel is missing/stale, or the parameter type resolves to an unloaded assembly, or GetDeclaredSymbol returns null.
Common situations: Source generator running before dependencies are fully compiled; missing assembly references in the Compilation; incremental generator staleness; types from assemblies not referenced by the compilation.
Related errors
- Could not find type symbol for: {node}
- Failed to compile migration '{migrationId}'. Errors: {errors
- ArrayCreation: non-array type symbol: {implicitArrayCreation
- Could not find symbol for method invocation: {invocation}
- MemberAccess: Couldn't find symbol for member: {memberAccess
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/6f8a42340debf889.
Report an issue: GitHub.