dotnet/efcore · error · InvalidOperationException

MemberAccess: Couldn't find symbol for member

Error message

MemberAccess: Couldn't find symbol for member: {memberAccess}

What it means

Thrown by VisitMemberAccessExpression when Roslyn's GetSymbolInfo on a member access expression returns a null Symbol. The translator cannot determine what property, field, or nested type is being accessed without the symbol, so it throws InvalidOperationException. This is distinct from [208] — here the symbol itself is missing; in [208] the symbol exists but reflection can't find the member.

Solutions

  1. Ensure the project compiles cleanly before running precompilation — run dotnet build and fix all errors first.
  2. If the member is on an external type, verify the containing assembly is referenced and passed to Load() via additionalAssembly.
  3. Avoid dynamic-typed expressions inside precompiled queries — use strongly-typed variables.
  4. If accessing members of anonymous types, keep the anonymous type usage within the same query scope where the compiler can infer the type.

Example fix

// before — member access Roslyn can't resolve (dynamic or missing type)
var query = ctx.Blogs.Where(b => ((dynamic)b).UnknownProperty != null);

// after — strongly typed
var query = ctx.Blogs.Where(b => b.Name != null);
Defensive patterns

Strategy: validation

Validate before calling

// Before precompiling, verify all member accesses resolve to symbols
var unresolvedMembers = querySyntaxTree.DescendantNodes()
    .OfType<MemberAccessExpressionSyntax>()
    .Where(m => semanticModel.GetSymbolInfo(m).Symbol is null);
if (unresolvedMembers.Any())
    ReportError("Unresolved member access in precompiled query — check references and compile errors");

Prevention

When it happens

Trigger: A precompiled query accesses a member (property, field, nested type) that Roslyn cannot resolve. Causes include: the member doesn't exist in the referenced compilation (compile error), the access is through an error type, the semantic model is stale/incomplete, or the member access is on a dynamic-typed expression.

Common situations: Accessing members on objects whose type is defined in a not-yet-compiled or circularly-referenced project; accessing members through `dynamic` typed variables; stale semantic model after code edits without recompilation; accessing members of anonymous types across assembly boundaries where type inference fails; conditional member access on compiler-generated backing fields.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/edfd8c6c669d6d4e. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:772

    /// </summary>
    public override Expression VisitLiteralExpression(LiteralExpressionSyntax literal)
        => _semanticModel.GetTypeInfo(literal) is { ConvertedType: { } type }
            ? Constant(literal.Token.Value, ResolveType(type))
            : Constant(literal.Token.Value);

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public override Expression VisitMemberAccessExpression(MemberAccessExpressionSyntax memberAccess)
    {
        var expression = Visit(memberAccess.Expression);

        if (_semanticModel.GetSymbolInfo(memberAccess).Symbol is not { } memberSymbol)
        {
            throw new InvalidOperationException($"MemberAccess: Couldn't find symbol for member: {memberAccess}");
        }

        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);

View on GitHub (pinned to 3a2006ef56)