{"record":{"id":"35129a82dfe9c63f","repo":"dotnet/efcore","slug":"couldn-t-resolve-clr-type-name-in-assembly-a","errorCode":null,"errorMessage":"Couldn't resolve CLR type '{name}' in assembly '{assemblySymbol?.Name}'","messagePattern":"Couldn't resolve CLR type '(.+?)' in assembly '(.+?)'","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":1222,"sourceCode":"                var containingType = ResolveType(symbol.ContainingType);\n\n                return containingType.GetNestedType(name)\n                    ?? throw new InvalidOperationException(\n                        $\"Couldn't find nested type '{name}' on containing type '{containingType.Name}'\");\n            }\n\n            return GetClrTypeFromAssembly(typeSymbol.ContainingAssembly, name);\n        }\n\n        Type GetClrTypeFromAssembly(IAssemblySymbol? assemblySymbol, string name)\n            => (assemblySymbol is null\n                    ? Type.GetType(name)!\n                    : Type.GetType($\"{name}, {assemblySymbol.Name}\"))\n                // If we can't find the Type, check the assembly where the user's DbContext type lives; this is primarily to support\n                // testing, where user code is in an assembly that's built as part of the the test and loaded into a specific\n                // AssemblyLoadContext (which gets unloaded later).\n                ?? _additionalAssembly?.GetType(name)\n                ?? throw new InvalidOperationException(\n                    $\"Couldn't resolve CLR type '{name}' in assembly '{assemblySymbol?.Name}'\");\n\n        Dictionary<string[], Type> LoadAnonymousTypes(IAssemblySymbol assemblySymbol)\n        {\n            Assembly? assembly;\n            try\n            {\n                assembly = Assembly.Load(assemblySymbol.Name);\n            }\n            catch (FileNotFoundException)\n            {\n                // If we can't find the assembly, use the assembly where the user's DbContext type lives; this is primarily to support\n                // testing, where user code is in an assembly that's built as part of the the test and loaded into a specific\n                // AssemblyLoadContext (which gets unloaded later).\n                assembly = _additionalAssembly\n                    ?? throw new InvalidOperationException($\"Could not load assembly for IAssemblySymbol '{assemblySymbol.Name}'\");\n            }\n","sourceCodeStart":1204,"sourceCodeEnd":1240,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L1204-L1240","documentation":"Thrown by GetClrTypeFromAssembly when neither Type.GetType('name, assembly') nor _additionalAssembly?.GetType(name) can resolve the type. The fully-qualified type name could not be found in the referenced assembly or the additional-assembly fallback. Part of EF Core's precompiled-query C#-to-LINQ translation.","triggerScenarios":"Translating any type reference where the assembly is not loaded in the current AppLoadContext, or the type name does not match (renamed/moved namespace).","commonSituations":"Assembly not loaded at runtime; type moved between namespaces across versions; trimming/NativeAOT removing the type; AssemblyLoadContext isolation (especially in tests).","solutions":["Ensure the assembly containing the type is loaded, or pass it via the additionalAssembly parameter of CSharpToLinqTranslator.Load.","Confirm the type's full name matches across versions.","Disable trimming for that assembly if using NativeAOT/trimming."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-check that every referenced type is resolvable at runtime\nvar resolved = Type.GetType($\"{fullTypeName}, {assemblyName}\") ?? additionalAssembly?.GetType(fullTypeName);\nif (resolved is null)\n    throw new InvalidOperationException(\n        $\"Type '{fullTypeName}' cannot be loaded; add the assembly or pass additionalAssembly.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass all user/domain assemblies via the additionalAssembly parameter of CSharpToLinqTranslator.Load.","Disable assembly trimming for types referenced in precompiled queries."],"tags":["efcore","type-resolution","assembly-loading","reflection"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}