{"record":{"id":"f1af3f44ccfc5654","repo":"dotnet/efcore","slug":"encountered-unknown-identifier-name-identifierna","errorCode":null,"errorMessage":"Encountered unknown identifier name '{identifierName}', which doesn't correspond to a lambda parameter or captured variable","messagePattern":"Encountered unknown identifier name '(.+?)', which doesn't correspond to a lambda parameter or captured variable","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":458,"sourceCode":"        }\n\n        // The Translate entry point into the translator uses Roslyn's data flow analysis to locate all local variables flowing in\n        // (e.g. captured variables), and populates the _dataFlowsIn dictionary with them (with null values).\n        if (symbol is ILocalSymbol localSymbol && _dataFlowsIn.TryGetValue(localSymbol, out var memberExpression))\n        {\n            // The first time we see a flowing-in variable, we create MemberExpression for it and cache it in _dataFlowsIn.\n            return memberExpression\n                ?? (_dataFlowsIn[localSymbol] =\n                    Field(\n                        Constant(new FakeClosureFrameClass()),\n                        new FakeFieldInfo(\n                            typeof(FakeClosureFrameClass),\n                            ResolveType(localSymbol.Type),\n                            localSymbol.Name,\n                            localSymbol.NullableAnnotation is NullableAnnotation.NotAnnotated)));\n        }\n\n        throw new InvalidOperationException(\n            $\"Encountered unknown identifier name '{identifierName}', which doesn't correspond to a lambda parameter or captured variable\");\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    public override Expression VisitImplicitArrayCreationExpression(ImplicitArrayCreationExpressionSyntax implicitArrayCreation)\n    {\n        if (_semanticModel.GetTypeInfo(implicitArrayCreation).Type is not IArrayTypeSymbol arrayTypeSymbol)\n        {\n            throw new InvalidOperationException($\"ArrayCreation: non-array type symbol: {implicitArrayCreation}\");\n        }\n\n        if (arrayTypeSymbol.Rank > 1)\n        {","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L440-L476","documentation":"At the end of `VisitIdentifierName`, after excluding lambda parameters, the user's `DbContext`, and symbols that Roslyn's data-flow analysis reports as flowing in (`_dataFlowsIn`), the translator throws `InvalidOperationException`. The identifier refers to something it cannot model: not a parameter, not the context, and not a captured local.","triggerScenarios":"A precompiled query referencing an identifier that is a static member, a method group, a constant from an unreferenced scope, or any symbol Roslyn's `AnalyzeDataFlow(...).DataFlowsIn` did not include.","commonSituations":"Static properties/constants, namespace/type references used as values, or captures that the data-flow analysis excluded (e.g. conditionally initialized locals) appearing inside the translated query.","solutions":["Capture the external value into a local that clearly flows into the query so data-flow analysis picks it up.","Replace static/external references with a captured local variable assigned before the query.","If it is a type reference, use `typeof(T)` instead of the bare name."],"exampleFix":"// before\nvar q = ctx.Items.Where(i => i.Code == Constants.Code);   // static, not captured\n// after\nvar code = Constants.Code;\nvar q = ctx.Items.Where(i => i.Code == code);","handlingStrategy":"validation","validationCode":"// Ensure every non-parameter identifier is either the DbContext or a captured local flowing in.\nvar dataFlowsIn = semanticModel.AnalyzeDataFlow(node).DataFlowsIn;\nvar offenders = node.DescendantNodes().OfType<IdentifierNameSyntax>()\n    .Where(id =>\n    {\n        if (semanticModel.GetSymbolInfo(id).Symbol is not { } s) return true; // separate (217) error\n        if (s is not (ILocalSymbol or IFieldSymbol or IPropertySymbol)) return false;\n        var t = semanticModel.GetTypeInfo(id).Type;\n        if (t is not null && t.Name.Contains(\"DbSet\")) return true; // separate (218) error\n        return s is ILocalSymbol local && !dataFlowsIn.Contains(local);\n    })\n    .ToList();\nif (offenders.Count != 0)\n    throw new NotSupportedException(\n        \"Query references identifiers that are neither parameters, the DbContext, nor captured locals flowing in.\");\n\ntranslator.Translate(node, semanticModel);","typeGuard":null,"tryCatchPattern":"try { translator.Translate(node, semanticModel); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"doesn't correspond to a lambda parameter or captured variable\"))\n{ /* capture the external value into a local and rebuild */ }","preventionTips":["Capture static/external values into locals assigned right before the query so data-flow analysis sees them.","Use `typeof(T)` instead of bare type names used as values.","Avoid static members and method groups inside precompiled query lambdas."],"tags":["ef-core","precompiled-queries","expression-trees","captured-variables","unsupported-construct"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}