{"record":{"id":"53707f344d0996b3","repo":"icsharpcode/ILSpy","slug":"unexpected-rawtypekind-rawtypekind-0x-rawtypek","errorCode":null,"errorMessage":"Unexpected rawTypeKind: {rawTypeKind} (0x{rawTypeKind:x})","messagePattern":"Unexpected rawTypeKind: (.+?) \\(0x(.+?)\\)","errorType":"exception","errorClass":"BadImageFormatException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/Disassembler/DisassemblerSignatureTypeProvider.cs","lineNumber":241,"sourceCode":"\t\t\t\toutput.Write(']');\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tpublic Action<ILNameSyntax> GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind)\r\n\t\t{\r\n\t\t\treturn syntax => {\r\n\t\t\t\tswitch (rawTypeKind)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase 0x00:\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 0x11:\r\n\t\t\t\t\t\toutput.Write(\"valuetype \");\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 0x12:\r\n\t\t\t\t\t\toutput.Write(\"class \");\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($\"Unexpected rawTypeKind: {rawTypeKind} (0x{rawTypeKind:x})\");\r\n\t\t\t\t}\r\n\t\t\t\t((EntityHandle)handle).WriteTo(module, output, default);\r\n\t\t\t};\r\n\t\t}\r\n\r\n\t\tpublic Action<ILNameSyntax> GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)\r\n\t\t{\r\n\t\t\treturn syntax => {\r\n\t\t\t\tswitch (rawTypeKind)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase 0x00:\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 0x11:\r\n\t\t\t\t\t\toutput.Write(\"valuetype \");\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase 0x12:\r\n\t\t\t\t\t\toutput.Write(\"class \");\r\n\t\t\t\t\t\tbreak;\r","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/Disassembler/DisassemblerSignatureTypeProvider.cs#L223-L259","documentation":"BadImageFormatException from DisassemblerSignatureTypeProvider.GetTypeFromDefinition when the rawTypeKind byte decoded from a type signature is not one of the valid ECMA-335 codes (0x00 default, 0x11 valuetype, 0x12 class). Any other byte means corrupt signature metadata.","triggerScenarios":"Disassembling IL (ildasm-style output) for an assembly whose type-signature encoding contains an invalid type-kind byte: truncated, hand-edited, or obfuscated metadata.","commonSituations":"Corrupt PE files; IL produced by buggy or obfuscating tools; a truncated download of the assembly.","solutions":["Catch BadImageFormatException around the disassemble call and report the member as not disassemblable.","Verify the assembly with peverify or obtain a fresh copy; if it reproducibly fails on valid metadata, file an ILSpy issue."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    disassembler.Disassemble(module, entityHandle, output);\n} catch (BadImageFormatException ex) {\n    logger.Warning(\"Corrupt signature in {Module}: {Message}\", module.FileName, ex.Message);\n}","preventionTips":["Treat BadImageFormatException during disassembly as corrupt input, not a recoverable transient error.","Validate assemblies with peverify before batch disassembly."],"tags":["disassembly","il","bad-metadata","metadata"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}