{"record":{"id":"2ed49572ec8815bb","repo":"icsharpcode/ILSpy","slug":"could-not-find-type-definition-fulltypename-in-t","errorCode":null,"errorMessage":"Could not find type definition {fullTypeName} in type system.","messagePattern":"Could not find type definition (.+?) in type system\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs","lineNumber":1331,"sourceCode":"\t\t/// Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definitions.\r\n\t\t/// </remarks>\r\n\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","sourceCodeStart":1313,"sourceCodeEnd":1349,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs#L1313-L1349","documentation":"Thrown by DecompileType(FullTypeName) as InvalidOperationException when typeSystem.FindType(...).GetDefinition() returns null. The requested top-level type name is not present in the type system built from the assembly the CSharpDecompiler was constructed with.","triggerScenarios":"Passing a FullTypeName for a type that lives in a referenced assembly (not the loaded one), a name with the wrong namespace or generic arity, an obfuscated/renamed type, or a name formatted incorrectly for FullTypeName (e.g. reflection FullName with '+' nested separators instead of '/').","commonSituations":"Asking for System.* types while decompiling an application assembly; version mismatch where the type moved namespaces; generic-arity mismatch; malformed nested-type name.","solutions":["Resolve the name yourself first and check for null: decompiler.TypeSystem.FindType(name.TopLevelTypeName).GetDefinition().","Confirm the assembly actually contains the type by enumerating module.TypeDefinitions and matching the full name.","For nested types use the correct FullTypeName form (slash-separated nested names) and correct generic arity.","If the type is in a dependency, load and decompile that dependency assembly instead."],"exampleFix":"// before\nvar tree = decompiler.DecompileType(new FullTypeName(\"MyNamespace.MyType\"));\n\n// after\nvar name = new FullTypeName(\"MyNamespace.MyType\");\nvar def = decompiler.TypeSystem.FindType(name.TopLevelTypeName).GetDefinition();\nif (def == null)\n    throw new InvalidOperationException($\"'{name}' is not in {decompiler.TypeSystem.MainModule.AssemblyName}\");\nvar tree = decompiler.DecompileType(name);","handlingStrategy":"validation","validationCode":"var def = decompiler.TypeSystem.FindType(name.TopLevelTypeName).GetDefinition();\nif (def == null)\n    throw new InvalidOperationException($\"'{name}' is not in {decompiler.TypeSystem.MainModule.AssemblyName}\");\nvar tree = decompiler.DecompileType(name);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm the type name belongs to the loaded module before decompiling.","For nested or generic names use the FullTypeName forms ILSpy expects (slash nesting, backtick arity)."],"tags":["decompilation","type-resolution","metadata"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}