{"record":{"id":"b247ac527be6c727","repo":"dotnet/efcore","slug":"no-type-for-expression-elementaccessexpression-ex","errorCode":null,"errorMessage":"No type for expression {elementAccessExpression.Expression} in ElementAccessExpressionSyntax","messagePattern":"No type for expression (.+?) in ElementAccessExpressionSyntax","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":384,"sourceCode":"                return ArrayIndex(visitedExpression, Visit(arguments[0].Expression));\n\n            case INamedTypeSymbol:\n                var property = visitedExpression.Type\n                    .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;","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L366-L402","documentation":"`VisitElementAccessExpression` switches on `GetTypeInfo(elementAccessExpression.Expression).ConvertedType`; the `case null:` arm throws `InvalidOperationException` when the semantic model cannot determine the type of the expression being indexed (`obj[...]` where `obj` has no resolvable type).","triggerScenarios":"Translating an indexer expression `a[i]` where the type of `a` is unbound — typically because the `SemanticModel` is incomplete or the receiver's type is in an unreferenced assembly.","commonSituations":"Missing metadata references, or using a `SemanticModel` from a compilation that does not contain the receiver's type definition.","solutions":["Ensure the receiver's type assembly is referenced / passed as `additionalAssembly`.","Make sure the tree belongs to the compilation that built the `SemanticModel`.","Replace the indexer with an equivalent method call that resolves cleanly."],"exampleFix":"// before\ntranslator.Translate(indexNode, smWithMissingRefs);\n// after\nvar compilation = baseCompilation\n    .AddReferences(MetadataReference.CreateFromFile(typeof(ReceiverType).Assembly.Location));\ntranslator.Translate(indexNode, compilation.GetSemanticModel(tree));","handlingStrategy":"validation","validationCode":"// Ensure the indexer receiver has a resolvable converted type.\nvar converted = semanticModel.GetTypeInfo(elementAccess.Expression).ConvertedType;\nif (converted is null)\n    throw new InvalidOperationException(\n        \"The indexer receiver has no resolvable type. Add the needed references and ensure the tree is in the compilation.\");\n\ntranslator.Translate(elementAccess, semanticModel);","typeGuard":null,"tryCatchPattern":"try { translator.Translate(node, semanticModel); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No type for expression\") && ex.Message.Contains(\"ElementAccessExpressionSyntax\"))\n{ /* add references / fix tree membership, then retry */ }","preventionTips":["Reference the assembly that defines the indexer receiver's type.","Keep the tree inside the compilation that builds the `SemanticModel`.","Avoid indexers over types from unloaded assemblies."],"tags":["ef-core","precompiled-queries","roslyn","type-resolution","indexers"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}