{"record":{"id":"74f7fd803804ea29","repo":"dotnet/efcore","slug":"debuginfo-nodes-are-not-supporting-when-translatin","errorCode":null,"errorMessage":"DebugInfo nodes are not supporting when translating expression trees to C#","messagePattern":"DebugInfo nodes are not supporting when translating expression trees to C#","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs","lineNumber":1196,"sourceCode":"    /// </summary>\n    protected virtual ExpressionSyntax GenerateUnknownValue(object value)\n    {\n        var type = value.GetType();\n        return type.IsValueType\n            && value.Equals(type.GetDefaultValue())\n                ? DefaultExpression(Generate(type))\n                : value is IRelationalQuotableExpression relationalQuotableExpression\n                && Translate(relationalQuotableExpression.Quote()) is ExpressionSyntax expressionSyntax\n                    ? expressionSyntax\n                    : throw new NotSupportedException(\n                        $\"Encountered a constant of unsupported type '{value.GetType().Name}'. Only primitive constant nodes are supported.\"\n                        + Environment.NewLine\n                        + value);\n    }\n\n    /// <inheritdoc />\n    protected override Expression VisitDebugInfo(DebugInfoExpression node)\n        => throw new NotSupportedException(\"DebugInfo nodes are not supporting when translating expression trees to C#\");\n\n    /// <inheritdoc />\n    protected override Expression VisitDefault(DefaultExpression node)\n    {\n        Result = DefaultExpression(Generate(node.Type));\n\n        return node;\n    }\n\n    /// <inheritdoc />\n    protected override Expression VisitGoto(GotoExpression gotoNode)\n    {\n        Result = GotoStatement(SyntaxKind.GotoStatement, TranslateLabelTarget(gotoNode.Target));\n        return gotoNode;\n    }\n\n    /// <inheritdoc />\n    protected override Expression VisitInvocation(InvocationExpression invocation)","sourceCodeStart":1178,"sourceCodeEnd":1214,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs#L1178-L1214","documentation":"VisitDebugInfo throws NotSupportedException because DebugInfoExpression nodes (JIT sequence-point / debug-info markers) carry no information that maps to C# source. The translator is used by EF Core's precompiled-query and runtime-model source generators to render LINQ expression trees as C#, so a node type with no source equivalent is rejected outright.","triggerScenarios":"An expression tree fed to the translator (a precompiled query lambda or a model-building lambda) contains a DebugInfoExpression. The C# compiler never emits these for normal user lambdas; they appear when an ExpressionVisitor/rewriter or a manual Expression.DebugInfo(...) call inserts one, or a third-party library emits debug-info nodes into a tree EF Core then tries to precompile.","commonSituations":"Custom expression-tree rewriting middleware that annotates trees with DebugInfo; programmatically constructed query trees passed through EF Core's precompiled-query source generator; integrating a library that instruments expression trees.","solutions":["Strip DebugInfoExpression nodes from the tree before precompilation using an ExpressionVisitor that overrides VisitDebugInfo to return the node without re-emitting it (or skips it from parent block enumerations).","Stop inserting Expression.DebugInfo(...) into lambdas consumed by EF Core precompiled queries.","If the node originates from a third-party extension, report it — EF Core's translator should never see debug info for compiler-generated query lambdas."],"exampleFix":"// before (tree builder inserts debug info)\nvar body = Expression.Block(\n    Expression.DebugInfo(Document, 0, 0, 0, 10),\n    originalBody);\n// after (strip debug-info nodes before handing to EF Core)\npublic class DebugInfoStripper : ExpressionVisitor {\n    protected override Expression VisitDebugInfo(DebugInfoExpression node) => node; // dropped from block assembly\n}","handlingStrategy":"validation","validationCode":"// Run before precompiling: assert no DebugInfo nodes exist\npublic sealed class DebugInfoDetector : ExpressionVisitor {\n    public bool Found;\n    protected override Expression VisitDebugInfo(DebugInfoExpression node) { Found = true; return node; }\n}\nvar d = new DebugInfoDetector(); d.Visit(lambda.Body);\nif (d.Found) throw new InvalidOperationException(\"Tree contains DebugInfo nodes; strip them first.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never insert Expression.DebugInfo into trees consumed by EF Core precompiled queries.","If you rewrite trees, override VisitDebugInfo to drop debug-info nodes.","Keep third-party expression-tree instrumentation out of precompiled-query lambdas."],"tags":["ef-core","linq","expression-tree","code-generation","precompiled-queries"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}