dotnet/efcore · error · InvalidOperationException
Got translated node of type '{Result?.GetType().Name ?? "<nu
Error message
Got translated node of type '{Result?.GetType().Name ?? "<null>"}' instead of the expected {typeof(T)} What it means
Thrown by the generic Translate<T> helper when the translated Result is not assignable to T. The visitor produced a syntax node of a different kind than the caller expected (e.g. expected an ExpressionSyntax but got a StatementSyntax). Part of EF Core's LINQ-to-C# syntax translation.
Source
Thrown at src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs:240
{
Visit(node);
return Result;
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual T Translate<T>(Expression? node)
where T : CSharpSyntaxNode
{
Visit(node);
return Result as T
?? throw new InvalidOperationException(
$"Got translated node of type '{Result?.GetType().Name ?? "<null>"}' instead of the expected {typeof(T)}");
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual ExpressionSyntax Translate(Expression expression, IdentifierNameSyntax? lowerableAssignmentVariable)
{
Check.DebugAssert(
_context is ExpressionContext.Expression or ExpressionContext.ExpressionLambda,
"Cannot lower in statement context");
return expression switch
{
SwitchExpression switchExpressionView on GitHub (pinned to dbf9771522)
Solutions
- Inspect the actual translated node type reported in the message to understand what was produced.
- Restructure the expression to produce the expected node kind.
- Report the unsupported node type or extend the translator to handle it.
Defensive patterns
Strategy: try-catch
Try / catch
try
{
var syntax = translator.Translate<ExpressionSyntax>(expr);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("instead of the expected"))
{
// The expression produced a different syntax kind; log the actual kind and fall back
// to statement-form translation or simplify the expression.
logger.LogWarning("Expression translated to unexpected node: {Message}", ex.Message);
} Prevention
- Before calling Translate<T>, confirm the expression node kind maps to the expected syntax type.
- Inspect the message for the actual node type to guide restructuring.
When it happens
Trigger: Any internal call to Translate<T> where the expression tree node translates to an unexpected syntax kind - e.g. an expression that lifts to a statement, or an unhandled node type.
Common situations: Expression tree shapes unsupported by the translator; translator bugs handling certain node types; EF Core version changes introducing new expression shapes.
Related errors
- Lifted expressions remaining at top-level in expression cont
- Power over non-double operands
- Encountered a constant of unsupported type '{value.GetType()
- Lambda with null expression body
- Lambda with modifiers not supported: {lambda.Modifiers}
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/107d2c42c7587e72.
Report an issue: GitHub.