{"record":{"id":"864919150594db7c","repo":"dotnet/efcore","slug":"could-not-find-type-symbol-for-fullyqualifiedmet","errorCode":null,"errorMessage":"Could not find type symbol for: {fullyQualifiedMetadataName}","messagePattern":"Could not find type symbol for: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":68,"sourceCode":"    /// <param name=\"userDbContext\">An instance of the user's <see cref=\"DbContext\" />.</param>\n    /// <param name=\"additionalAssembly\">An optional additional assemblies to resolve CLR types from.</param>\n    /// <remarks>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </remarks>\n    public virtual void Load(Compilation compilation, DbContext userDbContext, Assembly? additionalAssembly = null)\n    {\n        _compilation = compilation;\n        _userDbContext = userDbContext;\n        _additionalAssembly = additionalAssembly;\n        _userDbContextSymbol = GetTypeSymbolOrThrow(userDbContext.GetType().FullName!);\n        _formattableStringSymbol = GetTypeSymbolOrThrow(\"System.FormattableString\");\n\n        INamedTypeSymbol GetTypeSymbolOrThrow(string fullyQualifiedMetadataName)\n            => _compilation.GetTypeByMetadataName(fullyQualifiedMetadataName)\n                ?? throw new InvalidOperationException(\"Could not find type symbol for: \" + fullyQualifiedMetadataName);\n    }\n\n    private readonly Stack<ImmutableDictionary<string, ParameterExpression>> _parameterStack\n        = new([ImmutableDictionary<string, ParameterExpression>.Empty]);\n\n    private readonly Dictionary<ISymbol, MemberExpression?> _dataFlowsIn = [with(SymbolEqualityComparer.Default)];\n\n    /// <summary>\n    ///     Translates a Roslyn syntax tree into a LINQ expression tree.\n    /// </summary>\n    /// <param name=\"node\">The Roslyn syntax node to be translated.</param>\n    /// <param name=\"semanticModel\">\n    ///     The <see cref=\"SemanticModel\" /> for the Roslyn <see cref=\"SyntaxTree\" /> of which <paramref name=\"node\" /> is a part.\n    /// </param>\n    /// <returns>A LINQ expression tree translated from the provided <paramref name=\"node\" />.</returns>\n    /// <remarks>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L50-L86","documentation":"`CSharpToLinqTranslator.Load` calls the local `GetTypeSymbolOrThrow`, which does `_compilation.GetTypeByMetadataName(fullyQualifiedMetadataName)` and throws `InvalidOperationException` if it returns null. It is invoked for the user's DbContext type (`userDbContext.GetType().FullName`) and for `System.FormattableString`, so the compilation passed to `Load` must be able to resolve both.","triggerScenarios":"Calling `translator.Load(compilation, userDbContext, additionalAssembly)` with a Roslyn `Compilation` that has no metadata reference to the assembly defining the DbContext (or to the core library that defines `System.FormattableString`). This path is exercised by EF Core's precompiled-query pipeline.","commonSituations":"Building the `Compilation` without adding `MetadataReference.CreateFromFile(typeof(MyContext).Assembly.Location)`, targeting a TFM whose core assembly differs, or passing a `Compilation` assembled from the wrong syntax trees.","solutions":["Add the DbContext's assembly as a metadata reference to the compilation before calling `Load`.","Ensure the compilation also references the core library that defines `System.FormattableString` (e.g. `typeof(FormattableString).Assembly`).","If the DbContext lives in a test ALC, pass that assembly via the `additionalAssembly` parameter."],"exampleFix":"// before\nvar compilation = CSharpCompilation.Create(\"q\").AddSyntaxTrees(tree);\ntranslator.Load(compilation, dbContext);\n// after\nvar compilation = CSharpCompilation.Create(\"q\")\n    .AddSyntaxTrees(tree)\n    .AddReferences(\n        MetadataReference.CreateFromFile(dbContext.GetType().Assembly.Location),\n        MetadataReference.CreateFromFile(typeof(FormattableString).Assembly.Location));\ntranslator.Load(compilation, dbContext);","handlingStrategy":"validation","validationCode":"// Verify the compilation can resolve the DbContext and FormattableString before Load.\nstatic void EnsureReferences(CSharpCompilation compilation, Type dbContextType)\n{\n    if (compilation.GetTypeByMetadataName(dbContextType.FullName!) is null)\n        throw new InvalidOperationException(\n            $\"Compilation is missing a reference to the assembly defining {dbContextType.FullName}.\");\n    if (compilation.GetTypeByMetadataName(\"System.FormattableString\") is null)\n        throw new InvalidOperationException(\n            \"Compilation is missing a reference to the core library (System.FormattableString).\");\n}\n\nEnsureReferences(compilation, typeof(MyContext));\ntranslator.Load(compilation, dbContext);","typeGuard":null,"tryCatchPattern":"// Wrap Load in a try/catch focused on the type-symbol resolution failure.\ntry\n{\n    translator.Load(compilation, dbContext, additionalAssembly);\n}\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Could not find type symbol for:\"))\n{\n    // Add the missing metadata reference and retry, or report a clear config error.\n    throw new InvalidOperationException(\n        \"The Roslyn compilation cannot resolve a required type. \" +\n        \"Add MetadataReferences for the DbContext assembly and the BCL.\", ex);\n}","preventionTips":["Always add `MetadataReference.CreateFromFile(typeof(MyContext).Assembly.Location)` to the compilation.","Include the core-library reference so `System.FormattableString` resolves.","For test ALCs, pass the user assembly via the `additionalAssembly` parameter."],"tags":["ef-core","precompiled-queries","roslyn","compilation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}