{"record":{"id":"dd00c81f88af7cdc","repo":"icsharpcode/ILSpy","slug":"unexpected-member-type","errorCode":null,"errorMessage":"Unexpected member type","messagePattern":"Unexpected member type","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs","lineNumber":2019,"sourceCode":"\t\t\t\t\t\t}\r\n\t\t\t\t\t\tentityDecl = DoDecompile(method, decompileRun, decompilationContext.WithCurrentMember(method), null);\r\n\t\t\t\t\t\tentityMap.Add(method, entityDecl);\r\n\t\t\t\t\t\tforeach (var helper in AddInterfaceImplHelpers(entityDecl, method, typeSystemAstBuilder))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tentityMap.Add(method, helper);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase IEvent @event:\r\n\t\t\t\t\t\tentityDecl = DoDecompile(@event, decompileRun, decompilationContext.WithCurrentMember(@event));\r\n\t\t\t\t\t\tentityMap.Add(@event, entityDecl);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tcase ITypeDefinition type:\r\n\t\t\t\t\t\tentityDecl = DoDecompile(type, decompileRun, decompilationContext.WithCurrentTypeDefinition(type));\r\n\t\t\t\t\t\tSetNewModifier(entityDecl);\r\n\t\t\t\t\t\tentityMap.Add(type, entityDecl);\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tthrow new ArgumentOutOfRangeException(\"Unexpected member type\");\r\n\t\t\t\t}\r\n\r\n\t\t\t\tEnqueueReferencedMembers(entityDecl);\r\n\r\n\t\t\t\tvoid EnqueueReferencedMembers(EntityDeclaration decl)\r\n\t\t\t\t{\r\n\t\t\t\t\tforeach (var node in decl.Descendants)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tvar rr = node.GetResolveResult();\r\n\t\t\t\t\t\tif (rr is MemberResolveResult mrr\r\n\t\t\t\t\t\t\t&& mrr.Member.DeclaringTypeDefinition == typeDef\r\n\t\t\t\t\t\t\t&& !(mrr.Member is IMethod { IsLocalFunction: true }))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tworkList.Enqueue(mrr.Member);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (rr is TypeResolveResult trr\r\n\t\t\t\t\t\t\t&& trr.Type.GetDefinition()?.DeclaringTypeDefinition == typeDef)\r\n\t\t\t\t\t\t{\r","sourceCodeStart":2001,"sourceCodeEnd":2037,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs#L2001-L2037","documentation":"ArgumentOutOfRangeException('Unexpected member type') from the DoDecompileMember local function inside DoDecompile(ITypeDefinition). The switch handles IField, IProperty, IMethod, IEvent and nested ITypeDefinition; the default branch is effectively an internal assertion that the type system returned an entity of an unrecognized kind. With standard ECMA-335 metadata every member is one of those kinds, so reaching this means an internal inconsistency or a non-standard entity implementation.","triggerScenarios":"A custom ITypeDefinition/IEntity implementation that yields a member not assignable to field/property/method/event/type; an internal bug after a type-system change; a corrupted member table yielding an entity of an unexpected runtime type.","commonSituations":"Plugging a custom metadata provider; very rare with real PE files, where it usually indicates an ILSpy bug.","solutions":["Catch ArgumentOutOfRangeException (or the wrapping DecompilerException) around the type decompile to keep the batch alive.","Inspect the entity's runtime type and report it as an ILSpy issue with the assembly and the offending type token."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    var tree = decompiler.Decompile(typeHandle);\n} catch (DecompilerException ex) when (ex.InnerException is ArgumentOutOfRangeException) {\n    logger.Error(\"Internal: unrecognized member kind in {Entity}\", ex.DecompiledEntity?.FullName);\n}","preventionTips":["Treat this as an internal assertion; report the offending entity and assembly to the ILSpy project.","Keep batch decompilation resilient by isolating each type in its own try/catch."],"tags":["decompilation","internal-assertion","metadata"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}