dotnet/efcore · error · InvalidOperationException
MemberAccess: couldn't find member '{memberSymbol.Name}': {m
Error message
MemberAccess: couldn't find member '{memberSymbol.Name}': {memberAccess} What it means
The member symbol resolved via Roslyn, but reflection lookup (GetProperty/GetField/GetNestedType) on the containing type returned null. The member is visible to the compiler but not discoverable/accessible via reflection, so the translator cannot build the MemberExpression.
Source
Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:792
var containingType = ResolveType(memberSymbol.ContainingType);
var memberInfo = memberSymbol switch
{
IPropertySymbol p => (MemberInfo?)containingType.GetProperty(p.Name),
IFieldSymbol f => containingType.GetField(f.Name),
INamedTypeSymbol t => containingType.GetNestedType(t.Name),
null => throw new InvalidOperationException($"MemberAccess: Couldn't find symbol for member: {memberAccess}"),
_ => throw new NotSupportedException($"MemberAccess: unsupported member symbol '{memberSymbol.GetType().Name}': {memberAccess}")
};
switch (memberInfo)
{
case Type nestedType:
return Constant(nestedType);
case null:
throw new InvalidOperationException($"MemberAccess: couldn't find member '{memberSymbol.Name}': {memberAccess}");
}
// Enum field constant
if (containingType.IsEnum)
{
return Constant(Enum.Parse(containingType, memberInfo.Name), containingType);
}
// array.Length
return expression.Type.IsArray && memberInfo.Name == "Length"
? expression.Type.GetArrayRank() != 1
? throw new NotImplementedException("MemberAccess on multi-dimensional array")
: (Expression)ArrayLength(expression)
: MakeMemberAccess(
expression is ConstantExpression { Value: Type } ? null : expression,
memberInfo);
}
View on GitHub (pinned to dbf9771522)
Solutions
- Make the member public
- Add [InternalsVisibleTo] for the consuming assembly
- Ensure the assembly version referenced at build time matches the runtime load
- Avoid explicit-interface-only members in precompiled queries
Example fix
// before
internal string Secret { get; set; }
// after
public string Secret { get; set; } Defensive patterns
Strategy: validation
Validate before calling
// Confirm the member is reflection-accessible from the consuming assembly.
var pi = typeof(Entity).GetProperty("InternalProp", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (pi is null) { /* make public or add InternalsVisibleTo */ } Prevention
- Make members accessed in precompiled queries public, or grant InternalsVisibleTo
- Avoid explicit-interface-only members in queries
- Keep assembly versions consistent between build and runtime
When it happens
Trigger: Accessing an internal/private member across an assembly boundary without InternalsVisibleTo, an explicit interface implementation member, a compiler-generated backing member, or a member whose defining assembly version differs from what reflection loads.
Common situations: Internal properties on entities shared across projects; members present only in a newer/older assembly version than the runtime load; explicit interface implementation properties accessed without the interface.
Related errors
- Invocation: couldn't find method '{methodSymbol.Name}' on ty
- MemberAccess: Couldn't find symbol for member: {memberAccess
- ObjectCreation: Missing constructor: {objectCreation}
- ObjectCreation: couldn't find initialized member '{lValueSym
- ArrayCreation: non-array type symbol: {implicitArrayCreation
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/85cb46c8930dbac3.
Report an issue: GitHub.