{"record":{"id":"85cb46c8930dbac3","repo":"dotnet/efcore","slug":"memberaccess-couldn-t-find-member-membersymbol","errorCode":null,"errorMessage":"MemberAccess: couldn't find member '{memberSymbol.Name}': {memberAccess}","messagePattern":"MemberAccess: couldn't find member '(.+?)': (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":792,"sourceCode":"\n        var containingType = ResolveType(memberSymbol.ContainingType);\n        var memberInfo = memberSymbol switch\n        {\n            IPropertySymbol p => (MemberInfo?)containingType.GetProperty(p.Name),\n            IFieldSymbol f => containingType.GetField(f.Name),\n            INamedTypeSymbol t => containingType.GetNestedType(t.Name),\n\n            null => throw new InvalidOperationException($\"MemberAccess: Couldn't find symbol for member: {memberAccess}\"),\n            _ => throw new NotSupportedException($\"MemberAccess: unsupported member symbol '{memberSymbol.GetType().Name}': {memberAccess}\")\n        };\n\n        switch (memberInfo)\n        {\n            case Type nestedType:\n                return Constant(nestedType);\n\n            case null:\n                throw new InvalidOperationException($\"MemberAccess: couldn't find member '{memberSymbol.Name}': {memberAccess}\");\n        }\n\n        // Enum field constant\n        if (containingType.IsEnum)\n        {\n            return Constant(Enum.Parse(containingType, memberInfo.Name), containingType);\n        }\n\n        // array.Length\n        return expression.Type.IsArray && memberInfo.Name == \"Length\"\n            ? expression.Type.GetArrayRank() != 1\n                ? throw new NotImplementedException(\"MemberAccess on multi-dimensional array\")\n                : (Expression)ArrayLength(expression)\n            : MakeMemberAccess(\n                expression is ConstantExpression { Value: Type } ? null : expression,\n                memberInfo);\n    }\n","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L774-L810","documentation":"Thrown when Roslyn successfully resolved the member symbol (property, field, or nested type) but the corresponding reflection lookup — GetProperty, GetField, or GetNestedType — returned null on the resolved containing Type. The member exists in the Roslyn compilation but is not found on the loaded CLR type via reflection, indicating a mismatch between the compile-time view and the runtime metadata view.","triggerScenarios":"A precompiled query accesses a member where: the member is an explicit interface implementation (metadata name differs from source name), the member was renamed between the referenced package version and the loaded version, the member is compiler-generated (e.g. anonymous type property whose reflection lookup path differs), or the containing type was loaded from a different assembly than expected.","commonSituations":"Version skew between the NuGet package at compile time and at precompilation time; accessing members through base types where reflection needs BindingFlags to find protected members; explicit interface implementations whose GetProperty(name) returns null because the property is implemented explicitly; accessing members on types from satellite/secondary assemblies not loaded; shadowed/new members where the base type's member is expected.","solutions":["Check for assembly version mismatches between compile-time references and the assemblies loaded during precompilation.","If the member is an explicit interface implementation, access it through the interface type or cast to the interface before accessing.","If the member is protected/internal, ensure the declaring type and member are accessible to the precompilation assembly.","Verify the containing type is resolved correctly — debug by checking ResolveType(memberSymbol.ContainingType) returns the expected Type.","If using multi-targeting, ensure the correct TFM's assembly is loaded."],"exampleFix":"// before — explicit interface implementation, reflection GetProperty fails\nvar query = ctx.Items.Where(x => ((ICollection<Item>)x).Count > 0);\n\n// after — access through a public property or restructure\nvar query = ctx.Items.Where(x => x.SubItems.Count > 0);","handlingStrategy":"validation","validationCode":"// Before precompiling, verify resolved members are findable via reflection\nforeach (var memberAccess in querySyntaxTree.DescendantNodes().OfType<MemberAccessExpressionSyntax>())\n{\n    if (semanticModel.GetSymbolInfo(memberAccess).Symbol is { } symbol)\n    {\n        var containingType = ResolveTypeForCheck(symbol.ContainingType);\n        MemberInfo? found = symbol switch\n        {\n            IPropertySymbol p => containingType.GetProperty(p.Name),\n            IFieldSymbol f => containingType.GetField(f.Name),\n            INamedTypeSymbol t => containingType.GetNestedType(t.Name),\n            _ => null\n        };\n        if (found is null && symbol is IPropertySymbol or IFieldSymbol or INamedTypeSymbol)\n            ReportError($\"Member '{symbol.Name}' not found via reflection on {containingType.Name}\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep NuGet package versions consistent between compile-time references and the precompilation environment.","Avoid explicit interface implementation member access inside precompiled queries.","Pass all relevant assemblies via additionalAssembly to Load().","Use multi-targeting-aware precompilation to ensure the correct TFM assembly is loaded.","Avoid accessing protected/internal members from different assemblies."],"tags":["precompiled-queries","roslyn","reflection","member-access","assembly-version","expression-tree"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}