{"record":{"id":"addc25382b68847d","repo":"dotnet/efcore","slug":"couldn-t-find-nested-type-name-on-containing-t","errorCode":null,"errorMessage":"Couldn't find nested type '{name}' on containing type '{containingType.Name}'","messagePattern":"Couldn't find nested type '(.+?)' on containing type '(.+?)'","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs","lineNumber":1207,"sourceCode":"            {\n                return typeof(Nullable<>);\n            }\n\n            var name = symbol.ContainingType is null\n                ? typeSymbol.ToDisplayString(QualifiedTypeNameSymbolDisplayFormat)\n                : typeSymbol.Name;\n\n            if (symbol.IsGenericType)\n            {\n                name += '`' + symbol.Arity.ToString();\n            }\n\n            if (symbol.ContainingType is not null)\n            {\n                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)","sourceCodeStart":1189,"sourceCodeEnd":1225,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs#L1189-L1225","documentation":"Thrown by GetClrType when containingType.GetNestedType(name) returns null. The CLR reflection lookup for a nested type (e.g. Outer.Inner) on its containing type failed - the nested type is not found via reflection on the resolved containing type. Part of EF Core's precompiled-query C#-to-LINQ translation.","triggerScenarios":"Translating a reference to a nested type where GetNestedType returns null: private/internal nested types, nested generics with mismatched arity suffix, or types removed across versions.","commonSituations":"Non-public nested types; nested generic types where arity suffix computation differs; obfuscated/renamed types; assembly version mismatch where the nested type was removed or relocated.","solutions":["Verify the nested type exists and is accessible via reflection in the loaded assembly version.","Check for assembly version mismatches between compile-time and runtime.","Ensure the nested type's visibility (public) allows reflection lookup."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before translating, verify nested types are reflectable\nvar nested = containingType.GetNestedType(name,\n    System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);\nif (nested is null)\n    throw new InvalidOperationException(\n        $\"Nested type '{name}' not found on '{containingType.FullName}'.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the runtime assembly version in sync with the compile-time references.","Prefer top-level types over deeply nested types referenced in translatable queries."],"tags":["efcore","reflection","nested-types","type-resolution"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}