{"record":{"id":"a01cca4762068d85","repo":"dotnet/efcore","slug":"couldn-t-find-type-symbol-for-type","errorCode":null,"errorMessage":"Couldn't find type symbol for: {type}","messagePattern":"Couldn't find type symbol for: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs","lineNumber":1287,"sourceCode":"            return compilation.CreateArrayTypeSymbol(elementSymbol, type.GetArrayRank());\n        }\n\n        if (type.IsGenericType && !type.IsGenericTypeDefinition)\n        {\n            var genericDefinition = (INamedTypeSymbol)GetTypeSymbol(\n                compilation,\n                type.GetGenericTypeDefinition());\n\n            var typeArguments = type\n                .GetGenericArguments()\n                .Select(t => GetTypeSymbol(compilation, t))\n                .ToArray();\n\n            return genericDefinition.Construct(typeArguments);\n        }\n\n        return type.FullName is null || compilation.GetTypeByMetadataName(type.FullName) is not { } typeSymbol\n            ? throw new InvalidOperationException($\"Couldn't find type symbol for: {type}\")\n            : typeSymbol;\n    }\n\n    [return: NotNullIfNotNull(nameof(name))]\n    private static string? SanitizeIdentifierName(string? name)\n    {\n        if (name == null)\n        {\n            return null;\n        }\n\n        if (string.IsNullOrWhiteSpace(name))\n        {\n            return \"_\";\n        }\n\n        var result = new string(\n            [.. name.Select(c => SyntaxFacts.IsIdentifierPartCharacter(c) ? c : '_')]);","sourceCodeStart":1269,"sourceCodeEnd":1305,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/PrecompiledQueryCodeGenerator.cs#L1269-L1305","documentation":"Thrown in PrecompiledQueryCodeGenerator.GetTypeSymbol (line 1287) when a runtime System.Type's FullName cannot be resolved by compilation.GetTypeByMetadataName. After handling arrays and constructed generics, GetTypeSymbol falls back to looking the type up by its FullName in the analysis compilation; if that returns null it throws InvalidOperationException. The type is not visible to the Roslyn compilation performing code generation.","triggerScenarios":"Precompiling a query that references a type (entity, value, or parameter type) whose assembly is not referenced by the Roslyn Compilation, or whose FullName is null (e.g. an anonymous type used in an unsupported position, a nested type with an unspeakable name, or a type from an unloaded assembly). GetTypeSymbol returns null from GetTypeByMetadataName and throws.","commonSituations":"The project being analyzed is missing a reference to the assembly that defines a type used in the query. The type lives in a source-generated assembly not yet produced when the analyzer runs. A type with no resolvable FullName (anonymous/unspeakable) reaches type-symbol resolution. Stale/incremental analysis that hasn't loaded all references.","solutions":["Add the missing assembly reference to the project so the type is visible to the analysis compilation.","Ensure any source-generated types are generated before precompiled-query analysis runs (check generator ordering / build target).","Replace the unresolvable type with a concrete, named type defined in a referenced assembly.","Clean and rebuild to refresh the analyzer's view of referenced assemblies."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm the type is resolvable in the compilation before generating\nif (type.FullName is null || compilation.GetTypeByMetadataName(type.FullName) is null)\n{ /* add missing reference or exclude query */ }","typeGuard":null,"tryCatchPattern":"try { /* generate */ }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Couldn't find type symbol\"))\n{ /* add the missing assembly reference, then retry */ }","preventionTips":["Keep the analyzed project's assembly references complete.","Ensure source-generated types exist before analysis runs.","Use concrete, named types from referenced assemblies in precompiled queries."],"tags":["ef-core","precompiled-query","type-resolution","roslyn","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}