{"record":{"id":"107d2c42c7587e72","repo":"dotnet/efcore","slug":"got-translated-node-of-type-result-gettype-na","errorCode":null,"errorMessage":"Got translated node of type '{Result?.GetType().Name ?? \"<null>\"}' instead of the expected {typeof(T)}","messagePattern":"Got translated node of type '(.+?)' instead of the expected (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs","lineNumber":240,"sourceCode":"    {\n        Visit(node);\n\n        return Result;\n    }\n\n    /// <summary>\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    /// </summary>\n    protected virtual T Translate<T>(Expression? node)\n        where T : CSharpSyntaxNode\n    {\n        Visit(node);\n\n        return Result as T\n            ?? throw new InvalidOperationException(\n                $\"Got translated node of type '{Result?.GetType().Name ?? \"<null>\"}' instead of the expected {typeof(T)}\");\n    }\n\n    /// <summary>\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    /// </summary>\n    protected virtual ExpressionSyntax Translate(Expression expression, IdentifierNameSyntax? lowerableAssignmentVariable)\n    {\n        Check.DebugAssert(\n            _context is ExpressionContext.Expression or ExpressionContext.ExpressionLambda,\n            \"Cannot lower in statement context\");\n\n        return expression switch\n        {\n            SwitchExpression switchExpression","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs#L222-L258","documentation":"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.","triggerScenarios":"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.","commonSituations":"Expression tree shapes unsupported by the translator; translator bugs handling certain node types; EF Core version changes introducing new expression shapes.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    var syntax = translator.Translate<ExpressionSyntax>(expr);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"instead of the expected\"))\n{\n    // The expression produced a different syntax kind; log the actual kind and fall back\n    // to statement-form translation or simplify the expression.\n    logger.LogWarning(\"Expression translated to unexpected node: {Message}\", ex.Message);\n}","preventionTips":["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."],"tags":["efcore","expression-trees","type-mismatch","code-generation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}