{"record":{"id":"4c8cc1fc8e1ff693","repo":"icsharpcode/ILSpy","slug":"implementation-must-either-be-an-index-into-the-fi","errorCode":null,"errorMessage":"Implementation must either be an index into the File, ExportedType or AssemblyRef table.","messagePattern":"Implementation must either be an index into the File, ExportedType or AssemblyRef table\\.","errorType":"exception","errorClass":"BadImageFormatException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs","lineNumber":2174,"sourceCode":"\t\t\t\t\t\t\tif (declaringType.Implementation.Kind == HandleKind.ExportedType)\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tdeclaringType = metadata.GetExportedType((ExportedTypeHandle)declaringType.Implementation);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\toutput.WriteLine();\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase HandleKind.AssemblyReference:\r\n\t\t\t\t\t\toutput.Write(\".assembly extern \");\r\n\t\t\t\t\t\tvar reference = metadata.GetAssemblyReference((AssemblyReferenceHandle)exportedType.Implementation);\r\n\t\t\t\t\t\toutput.Write(DisassemblerHelpers.Escape(metadata.GetString(reference.Name)));\r\n\t\t\t\t\t\toutput.WriteLine();\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new BadImageFormatException(\"Implementation must either be an index into the File, ExportedType or AssemblyRef table.\");\r\n\t\t\t\t}\r\n\t\t\t\tCloseBlock();\r\n\t\t\t}\r\n\t\t\tvar moduleDefinition = metadata.GetModuleDefinition();\r\n\r\n\t\t\toutput.WriteLine(\".module {0}\", metadata.GetString(moduleDefinition.Name));\r\n\t\t\tif (!skipMVID)\r\n\t\t\t{\r\n\t\t\t\toutput.WriteLine(\"// MVID: {0}\", metadata.GetGuid(moduleDefinition.Mvid).ToString(\"B\").ToUpperInvariant());\r\n\t\t\t}\r\n\r\n\t\t\tif (module is PEFile peFile)\r\n\t\t\t{\r\n\t\t\t\tvar headers = peFile.Reader.PEHeaders;\r\n\t\t\t\toutput.WriteLine(\".imagebase 0x{0:x8}\", headers.PEHeader.ImageBase);\r\n\t\t\t\toutput.WriteLine(\".file alignment 0x{0:x8}\", headers.PEHeader.FileAlignment);\r\n\t\t\t\toutput.WriteLine(\".stackreserve 0x{0:x8}\", headers.PEHeader.SizeOfStackReserve);\r\n\t\t\t\toutput.WriteLine(\".subsystem 0x{0:x} // {1}\", headers.PEHeader.Subsystem, headers.PEHeader.Subsystem.ToString());\r","sourceCodeStart":2156,"sourceCodeEnd":2192,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs#L2156-L2192","documentation":"BadImageFormatException while disassembling an ExportedType: its Implementation handle must index the File, ExportedType, or AssemblyRef table. Any other handle kind means corrupt ExportedType metadata, so the '.class extern' forwarding cannot be decoded.","triggerScenarios":"Disassembling a module whose .class extern (ExportedType) rows have an Implementation column pointing at an invalid table: malformed or hand-edited metadata.","commonSituations":"Corrupt or obfuscated assemblies; multi-module assemblies with damaged type-forwarding tables.","solutions":["Catch BadImageFormatException around the module-header / ExportedType disassembly and continue with the rest.","Validate with peverify and restore a clean copy of the assembly."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    disassembler.WriteAssemblyReferences(module); // includes ExportedType rows\n} catch (BadImageFormatException ex) {\n    logger.Warning(\"Corrupt ExportedType metadata in {Module}: {Message}\", module.FileName, ex.Message);\n}","preventionTips":["Treat BadImageFormatException while disassembling ExportedType rows as corrupt input.","Validate multi-module and obfuscated assemblies with peverify before disassembly."],"tags":["disassembly","il","bad-metadata","exported-type","metadata"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}