{"record":{"id":"7ddfba59f7038822","repo":"icsharpcode/ILSpy","slug":"type-fulltypename-was-not-found-in-the-module-be","errorCode":null,"errorMessage":"Type {fullTypeName} was not found in the module being decompiled, but only in {type.ParentModule!.Name}","messagePattern":"Type (.+?) was not found in the module being decompiled, but only in (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs","lineNumber":1333,"sourceCode":"\t\tpublic string DecompileTypesAsString(IEnumerable<TypeDefinitionHandle> types)\r\n\t\t{\r\n\t\t\treturn SyntaxTreeToString(DecompileTypes(types));\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t/// Decompile the given type.\r\n\t\t/// </summary>\r\n\t\t/// <remarks>\r\n\t\t/// Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definition.\r\n\t\t/// Note that decompiling types from modules other than the main module is not supported.\r\n\t\t/// </remarks>\r\n\t\tpublic SyntaxTree DecompileType(FullTypeName fullTypeName)\r\n\t\t{\r\n\t\t\tvar type = typeSystem.FindType(fullTypeName.TopLevelTypeName).GetDefinition();\r\n\t\t\tif (type == null)\r\n\t\t\t\tthrow new InvalidOperationException($\"Could not find type definition {fullTypeName} in type system.\");\r\n\t\t\tif (type.ParentModule != typeSystem.MainModule)\r\n\t\t\t\tthrow new NotSupportedException($\"Type {fullTypeName} was not found in the module being decompiled, but only in {type.ParentModule!.Name}\");\r\n\t\t\tvar decompilationContext = new SimpleTypeResolveContext(typeSystem.MainModule);\r\n\t\t\tvar namespaces = new HashSet<string>();\r\n\t\t\tsyntaxTree = new SyntaxTree();\r\n\t\t\tRequiredNamespaceCollector.CollectNamespaces(type.MetadataToken, module, namespaces);\r\n\t\t\tvar decompileRun = CreateDecompileRun(namespaces);\r\n\t\t\tDoDecompileTypes(new[] { (TypeDefinitionHandle)type.MetadataToken }, decompileRun, decompilationContext, syntaxTree);\r\n\t\t\tRunTransforms(syntaxTree, decompileRun, decompilationContext);\r\n\t\t\treturn syntaxTree;\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t/// Decompile the given type.\r\n\t\t/// </summary>\r\n\t\t/// <remarks>\r\n\t\t/// Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definition.\r\n\t\t/// </remarks>\r\n\t\tpublic string DecompileTypeAsString(FullTypeName fullTypeName)\r\n\t\t{\r","sourceCodeStart":1315,"sourceCodeEnd":1351,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs#L1315-L1351","documentation":"Thrown by DecompileType(FullTypeName) as NotSupportedException when the type resolves but its ParentModule is not the main module the CSharpDecompiler was built for. Decompiling a type from a referenced dependency is unsupported; only types owned by the decompiled module can be emitted.","triggerScenarios":"The FullTypeName resolves to a type the type system found in a referenced assembly rather than the module under decompilation. Common with type forwarding (TypeForwardedTo) or names shared across assemblies.","commonSituations":"Decompiling app A and asking for a type A only references from a framework DLL; type forwarding making the type resolve in another module.","solutions":["Check def.ParentModule == decompiler.TypeSystem.MainModule before calling DecompileType.","If you really need that type, construct a separate CSharpDecompiler over the assembly where it is actually defined."],"exampleFix":"// before\nvar tree = decompiler.DecompileType(name); // name lives in a referenced assembly\n\n// after\nvar def = decompiler.TypeSystem.FindType(name.TopLevelTypeName).GetDefinition()\n    ?? throw new InvalidOperationException($\"'{name}' not found\");\nif (def.ParentModule != decompiler.TypeSystem.MainModule)\n    throw new InvalidOperationException($\"'{name}' is in {def.ParentModule.Name}; decompile that module instead\");\nvar tree = decompiler.DecompileType(name);","handlingStrategy":"validation","validationCode":"var def = decompiler.TypeSystem.FindType(name.TopLevelTypeName).GetDefinition()\n    ?? throw new InvalidOperationException($\"'{name}' not found\");\nif (def.ParentModule != decompiler.TypeSystem.MainModule)\n    throw new InvalidOperationException($\"'{name}' is in {def.ParentModule.Name}; load and decompile that module instead\");\nvar tree = decompiler.DecompileType(name);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only DecompileType names owned by the main module.","For dependencies, construct a CSharpDecompiler over the dependency assembly."],"tags":["decompilation","type-resolution","module-scope"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}