{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs#L503-L539","documentation":"Thrown by the precompiled-query code generator when Roslyn's SemanticModel.GetInterceptableLocation returns null for a LINQ operator invocation. Precompiled queries depend on the [InterceptsLocation] feature, which requires the compiler to be able to attribute a precise source location for interception; if it cannot, generation cannot proceed and throws InvalidOperationException.","triggerScenarios":"Enabling precompiled queries on a project compiled with a Roslyn/.NET SDK version that does not support interceptors, or on an invocation syntax that is not eligible for interception (e.g. certain dynamic or partially-resolved calls).","commonSituations":"Targeting an older .NET SDK/TFM that lacks interceptor support; using a preview precompiled-query feature with an incompatible toolchain; source-generator ordering issues where the semantic model cannot resolve the invocation.","solutions":["Upgrade the .NET SDK to a version that supports [InterceptsLocation] (preview precompiled-query requirement).","Ensure the project targets a compatible TFM for precompiled queries.","Disable precompiled queries for the affected query or project until the toolchain supports interception."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Detect interceptor support before enabling precompiled queries\nvar sdkSupportsInterceptors = typeof(System.Runtime.CompilerServices.InterceptsLocationAttribute).Assembly.GetType(\"System.Runtime.CompilerServices.InterceptsLocationAttribute\") is not null;\nif (!sdkSupportsInterceptors) { /* disable precompiled queries */ }","typeGuard":null,"tryCatchPattern":"try { generator.Generate(/*...*/); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"interceptable location\"))\n{ /* fall back to non-precompiled execution, or instruct user to upgrade SDK */ }","preventionTips":["Pin the project to a .NET SDK that supports [InterceptsLocation].","Gate precompiled-query generation behind a toolchain capability check.","Provide a fallback path that runs queries without interception."],"tags":["precompiled-queries","roslyn","interceptors","source-generator","sdk-version"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}