{"record":{"id":"926e86212a29e469","repo":"dotnet/efcore","slug":"elementaccessexpressionsyntax-over-non-array","errorCode":null,"errorMessage":"ElementAccessExpressionSyntax over non-array","messagePattern":"ElementAccessExpressionSyntax over non-array","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":388,"sourceCode":"                    .GetProperties()\n                    .Select(p => new { Property = p, IndexParameters = p.GetIndexParameters() })\n                    .Where(t => t.IndexParameters.Length == arguments.Count\n                        && t.IndexParameters\n                            .Select(p => p.ParameterType)\n                            .SequenceEqual(arguments.Select(a => ResolveType(a.Expression))))\n                    .Select(t => t.Property)\n                    .FirstOrDefault();\n\n                Check.DebugAssert(property?.GetMethod is not null, \"No matching property found for ElementAccessExpressionSyntax\");\n\n                return Call(visitedExpression, property.GetMethod, arguments.Select(a => Visit(a.Expression)));\n\n            case null:\n                throw new InvalidOperationException(\n                    $\"No type for expression {elementAccessExpression.Expression} in {nameof(ElementAccessExpressionSyntax)}\");\n\n            default:\n                throw new NotImplementedException($\"{nameof(ElementAccessExpressionSyntax)} over non-array\");\n        }\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 VisitIdentifierName(IdentifierNameSyntax identifierName)\n    {\n        if (_parameterStack.Peek().TryGetValue(identifierName.Identifier.Text, out var parameter))\n        {\n            return parameter;\n        }\n\n        var symbol = _semanticModel.GetSymbolInfo(identifierName).Symbol;\n","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L370-L406","documentation":"In `VisitElementAccessExpression` the `default:` arm throws `NotImplementedException(ElementAccessExpressionSyntax over non-array)` when the receiver's converted type is neither `IArrayTypeSymbol` nor `INamedTypeSymbol` — i.e. an indexer over a type the translator does not model (e.g. pointer/indexer-on-dynamic).","triggerScenarios":"An element access `x[i]` over a receiver whose converted type is something other than an array or a named type with an indexer (for example pointer indexing, `dynamic`, or an unbound symbol kind).","commonSituations":"Unsafe/pointer code or `dynamic` receivers appearing inside a precompiled query; rare in normal entity queries.","solutions":["Index only over arrays or over types that expose a real indexer property.","Hoist the access out of the query if it relies on pointer/dynamic semantics."],"exampleFix":"// before\nvar q = ctx.Items.Where(i => ((dynamic)i.Extra)[key] != null);\n// after\nvar extras = ctx.Items.Select(i => i.Extra).ToList();\nvar values = extras.Select(e => ((Dictionary<string,object>)e)[key]);","handlingStrategy":"validation","validationCode":"// Only allow indexers over arrays or named types (with a real indexer property).\nvar converted = semanticModel.GetTypeInfo(elementAccess.Expression).ConvertedType;\nif (converted is not (IArrayTypeSymbol or INamedTypeSymbol))\n    throw new NotSupportedException(\n        \"Element access is only supported over arrays or types with an indexer; pointer/dynamic indexing is unsupported.\");\n\ntranslator.Translate(elementAccess, semanticModel);","typeGuard":null,"tryCatchPattern":"try { translator.Translate(node, semanticModel); }\ncatch (NotImplementedException ex) when (ex.Message.Contains(\"ElementAccessExpressionSyntax over non-array\"))\n{ /* replace pointer/dynamic indexing with an indexer on a named type */ }","preventionTips":["Index only over arrays or types exposing a real indexer property.","Keep unsafe/pointer/dynamic code out of precompiled queries."],"tags":["ef-core","precompiled-queries","expression-trees","indexers","unsupported-construct"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}