dotnet/efcore · critical · InvalidOperationException

Could not find type symbol for: {fullyQualifiedMetadataName}

Error message

Could not find type symbol for: {fullyQualifiedMetadataName}

What it means

Thrown in QueryLocator.Symbols.GetTypeSymbolOrThrow (line 366) while loading the core symbols QueryLocator needs to locate queries in source. It resolves a fixed list (IQueryable`1, IQueryable, DbContext, DbSet`1, Enumerable, IEnumerable`1, Queryable, EntityFrameworkQueryableExtensions); if any is absent from the compilation it throws. Like error 288 it signals the analysis compilation is missing essential EF/Linq references, so query location cannot proceed.

Source

Thrown at src/EFCore.Design/Query/Internal/QueryLocator.cs:366

            _compilation = compilation;

            IQueryableOfT = GetTypeSymbolOrThrow("System.Linq.IQueryable`1");
            IQueryable = GetTypeSymbolOrThrow("System.Linq.IQueryable");
            DbContext = GetTypeSymbolOrThrow("Microsoft.EntityFrameworkCore.DbContext");
            DbSet = GetTypeSymbolOrThrow("Microsoft.EntityFrameworkCore.DbSet`1");

            Enumerable = GetTypeSymbolOrThrow("System.Linq.Enumerable");
            IEnumerableOfT = GetTypeSymbolOrThrow("System.Collections.Generic.IEnumerable`1");
            Queryable = GetTypeSymbolOrThrow("System.Linq.Queryable");
            EfQueryableExtensions = GetTypeSymbolOrThrow("Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions");
        }

        public static Symbols Load(Compilation compilation)
            => new(compilation);

        private INamedTypeSymbol GetTypeSymbolOrThrow(string fullyQualifiedMetadataName)
            => _compilation.GetTypeByMetadataName(fullyQualifiedMetadataName)
                ?? throw new InvalidOperationException("Could not find type symbol for: " + fullyQualifiedMetadataName);
    }
}

View on GitHub (pinned to dbf9771522)

Solutions

  1. Ensure the target project references EF Core (DbContext/DbSet/EntityFrameworkQueryableExtensions) and System.Linq.
  2. Run precompiled-query tooling only against projects that actually contain a DbContext.
  3. Verify the analyzer receives the project's full reference graph; fix any host that drops references.
  4. Restore packages and clean/rebuild so the compilation includes all referenced assemblies.
Defensive patterns

Strategy: validation

Validate before calling

// Confirm EF/Linq symbols are visible before QueryLocator loads
string[] required = {
    "Microsoft.EntityFrameworkCore.DbContext",
    "Microsoft.EntityFrameworkCore.DbSet`1",
    "System.Linq.Queryable"
};
if (required.Any(n => compilation.GetTypeByMetadataName(n) is null)) { /* add EF Core references */ }

Try / catch

try { QueryLocator.Symbols.Load(compilation); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Could not find type symbol"))
{ /* ensure the project references EF Core, then retry */ }

Prevention

When it happens

Trigger: QueryLocator.Symbols.Load runs on a Compilation where GetTypeByMetadataName returns null for one of the required types (e.g. Microsoft.EntityFrameworkCore.DbContext, Microsoft.EntityFrameworkCore.DbSet`1, or System.Linq.Queryable). GetTypeSymbolOrThrow throws immediately.

Common situations: The project being scanned for precompiled queries does not reference the EF Core assembly (no DbContext/DbSet symbols) or System.Linq. The analyzer host provided an incomplete Compilation. Running against a non-EF project by mistake. A stripped reference set in CI/source-generator contexts.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/c96d9d9222bf956c. Report an issue: GitHub.