{"record":{"id":"fd691a15a403837d","repo":"dotnet/efcore","slug":"couldn-t-get-interceptable-location-for-node","errorCode":null,"errorMessage":"Couldn't get interceptable location for: '{node}'.","messagePattern":"Couldn't get interceptable location for: '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs","lineNumber":521,"sourceCode":"                : returnTypeSymbol;\n\n        var returnElementTypeSymbol = returnTypeWithoutTask switch\n        {\n            IArrayTypeSymbol arrayTypeSymbol => arrayTypeSymbol.ElementType,\n            INamedTypeSymbol namedReturnType2\n                when namedReturnType2.AllInterfaces.Prepend(namedReturnType2)\n                    .Any(i => i.OriginalDefinition.Equals(_symbols.GenericEnumerable, SymbolEqualityComparer.Default)\n                        || i.OriginalDefinition.Equals(_symbols.GenericAsyncEnumerable, SymbolEqualityComparer.Default)\n                        || i.OriginalDefinition.Equals(_symbols.GenericEnumerator, SymbolEqualityComparer.Default))\n                => namedReturnType2.TypeArguments[0],\n            _ => null\n        };\n\n        // Output the interceptor method signature preceded by the [InterceptsLocation] attribute.\n        var interceptorName = $\"Query{queryNum}_{memberAccessSyntax.Name}{operatorNum}\";\n        var invocationSyntax = (InvocationExpressionSyntax)operatorSyntax;\n        var interceptableLocation = semanticModel.GetInterceptableLocation(invocationSyntax, cancellationToken)\n            ?? throw new InvalidOperationException(DesignStrings.CouldNotGetInterceptableLocation(operatorSyntax));\n        code.AppendLine(interceptableLocation.GetInterceptsLocationAttributeSyntax());\n        GenerateInterceptorMethodSignature();\n        code.AppendLine(\"{\").IncrementIndent();\n\n        // If this is the first query operator (no nested operator), cast the input source to IInfrastructure<DbContext> and extract the\n        // DbContext, create a new QueryContext, and wrap it all in a PrecompiledQueryContext that will flow through to the\n        // terminating operator, where the query will actually get executed.\n        // Otherwise, if this is a non-first operator, receive the PrecompiledQueryContext from the nested operator and flow it forward.\n        code.AppendLine(\n            \"var precompiledQueryContext = \"\n            + (operatorNum == 1\n                ? $\"new PrecompiledQueryContext<{sourceElementTypeName}>(((IInfrastructure<DbContext>){sourceVariableName}).Instance);\"\n                : $\"(PrecompiledQueryContext<{sourceElementTypeName}>){sourceVariableName};\"));\n\n        var declaredQueryContextVariable = false;\n\n        ProcessCapturedVariables();\n","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs#L503-L539","documentation":"Thrown in PrecompiledQueryCodeGenerator.GenerateOperatorInterceptor (line 521) when Roslyn's semanticModel.GetInterceptableLocation returns null for the operator's InvocationExpressionSyntax. Precompiled queries rely on the [InterceptsLocation] attribute, which requires a valid interceptable location; without one EF cannot emit the attribute that rewires the call site to the generated interceptor. It is a hard failure of the interceptor mechanism for that call site.","triggerScenarios":"Generating an interceptor for a LINQ operator invocation whose source location is not interceptable per Roslyn (e.g. the call is not at a position GetInterceptableLocation can anchor to, the invocation is in generated/synthesized code, or the C# language version does not support interceptors). The null result from GetInterceptableLocation triggers the InvalidOperationException.","commonSituations":"Targeting a C# language version older than the one supporting interceptors (the project's LangVersion is too low). The operator call lives in source that Roslyn cannot attribute (e.g. inside another source-generated file). A query form whose terminating/intermediate operator invocation Roslyn refuses to mark as interceptable. Mismatch between the analyzer's Roslyn version and what the project compiles with.","solutions":["Raise the project's C# language version to one that supports interceptors (set <LangVersion>latest</LangVersion> or the required preview version) and use a compatible SDK.","Move the query so the intercepted operator invocation lives in ordinary, editable user source rather than generated/synthesized code.","Simplify the query to isolate which operator invocation cannot be intercepted and restructure or drop it.","If the location genuinely cannot be intercepted, exclude that query from precompiled-query generation."],"exampleFix":"<!-- before -->\n<PropertyGroup>\n  <LangVersion>10.0</LangVersion>\n</PropertyGroup>\n\n<!-- after -->\n<PropertyGroup>\n  <LangVersion>latest</LangVersion>\n</PropertyGroup>","handlingStrategy":"validation","validationCode":"// Verify Roslyn can produce an interceptable location before committing to generation\nvar loc = semanticModel.GetInterceptableLocation(invocationSyntax, ct);\nif (loc is null) { /* exclude query or raise LangVersion */ }","typeGuard":null,"tryCatchPattern":"try { /* generate */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"interceptable location\"))\n{ /* report that the query cannot be intercepted; ensure LangVersion supports interceptors */ }","preventionTips":["Set <LangVersion>latest</LangVersion> (or the required preview) so interceptors are supported.","Keep intercepted calls in normal user source, not generated code.","Verify the SDK/Roslyn version supports interceptors."],"tags":["ef-core","precompiled-query","interceptors","roslyn","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}