dotnet/efcore · error · InvalidOperationException
MemberAccess: couldn't find member
Error message
MemberAccess: couldn't find member '{memberSymbol.Name}': {memberAccess} What it means
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.
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.
Example fix
// before — explicit interface implementation, reflection GetProperty fails var query = ctx.Items.Where(x => ((ICollection<Item>)x).Count > 0); // after — access through a public property or restructure var query = ctx.Items.Where(x => x.SubItems.Count > 0);
Defensive patterns
Strategy: validation
Validate before calling
// Before precompiling, verify resolved members are findable via reflection
foreach (var memberAccess in querySyntaxTree.DescendantNodes().OfType<MemberAccessExpressionSyntax>())
{
if (semanticModel.GetSymbolInfo(memberAccess).Symbol is { } symbol)
{
var containingType = ResolveTypeForCheck(symbol.ContainingType);
MemberInfo? found = symbol switch
{
IPropertySymbol p => containingType.GetProperty(p.Name),
IFieldSymbol f => containingType.GetField(f.Name),
INamedTypeSymbol t => containingType.GetNestedType(t.Name),
_ => null
};
if (found is null && symbol is IPropertySymbol or IFieldSymbol or INamedTypeSymbol)
ReportError($"Member '{symbol.Name}' not found via reflection on {containingType.Name}");
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invocation: couldn't find method
- Couldn't find single Add method on type
- Invocation: Found matches for generic method
- Invocation over non-member access
- MemberAccess: Couldn't find symbol for member
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/85cb46c8930dbac3.
Report an issue: GitHub.
Appendix: 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 3a2006ef56)