{"record":{"id":"55af2fa554c95efb","repo":"icsharpcode/ILSpy","slug":"handlekind-handle-kind-is-not-supported","errorCode":null,"errorMessage":"HandleKind {handle.Kind} is not supported!","messagePattern":"HandleKind (.+?) is not supported!","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs","lineNumber":1506,"sourceCode":"\t\t\t\t\tvar accessor = propDef.Getter ?? propDef.Setter;\r\n\t\t\t\t\tmemberInfo = extensionInfo.InfoOfExtensionMember((IMethod)accessor!.MemberDefinition).GetValueOrDefault();\r\n\t\t\t\t\tsubst = new TypeParameterSubstitution(memberInfo.ExtensionGroupingTypeParameters, null);\r\n\t\t\t\t\tpropDef = (IProperty)propDef.Specialize(subst);\r\n\t\t\t\t\tEntityDeclaration prop = DoDecompile(propDef, decompileRun, new SimpleTypeResolveContext(propDef), extensionInfo);\r\n\t\t\t\t\tsyntaxTree.Members.Add(prop);\r\n\t\t\t\t\tRemoveAttribute(prop, KnownAttribute.ExtensionMarker);\r\n\t\t\t\t\tif (propDef.Getter != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tRemoveAttribute(prop.GetChild(Slots.Getter)!, KnownAttribute.ExtensionMarker);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (propDef.Setter != null)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tRemoveAttribute(prop.GetChild(Slots.Setter)!, KnownAttribute.ExtensionMarker);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tRunTransforms(syntaxTree, decompileRun, new SimpleTypeResolveContext(propDef.DeclaringTypeDefinition));\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new NotSupportedException($\"HandleKind {handle.Kind} is not supported!\");\r\n\t\t\t}\r\n\t\t\treturn syntaxTree;\r\n\t\t}\r\n\r\n\t\tITypeDefinition? FindCommonDeclaringTypeDefinition(ITypeDefinition? a, ITypeDefinition? b)\r\n\t\t{\r\n\t\t\tif (a == null || b == null)\r\n\t\t\t\treturn null;\r\n\t\t\tvar declaringTypes = a.GetDeclaringTypeDefinitions();\r\n\t\t\tvar set = new HashSet<ITypeDefinition>(b.GetDeclaringTypeDefinitions());\r\n\t\t\treturn declaringTypes.FirstOrDefault(set.Contains);\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t/// Decompile the specified types and/or members.\r\n\t\t/// </summary>\r\n\t\tpublic string DecompileAsString(params EntityHandle[] definitions)\r\n\t\t{\r","sourceCodeStart":1488,"sourceCodeEnd":1524,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs#L1488-L1524","documentation":"NotSupportedException from DecompileExtension's default case: only TypeDefinition, MethodDefinition and PropertyDefinition handles are decompilable as extension members. Any other HandleKind (field, event, etc.) is rejected. C# extension members are methods only; properties appear for VB; fields and events are not valid extension members.","triggerScenarios":"Passing a FieldDefinitionHandle or EventDefinitionHandle (or any non-type/method/property handle) to DecompileExtension.","commonSituations":"Treating all members of an extension group uniformly; a handle selected by metadata-token comparison that happens to be a field/event.","solutions":["Gate the call on handle.Kind being TypeDefinition, MethodDefinition or PropertyDefinition before invoking DecompileExtension.","Filter extension-group members to the decompilable kinds (properties and methods)."],"exampleFix":"// before\nvar tree = decompiler.DecompileExtension(handle);\n\n// after\nif (handle.Kind is not (HandleKind.TypeDefinition or HandleKind.MethodDefinition or HandleKind.PropertyDefinition))\n    throw new NotSupportedException($\"DecompileExtension only takes type/method/property handles, got {handle.Kind}\");\nvar tree = decompiler.DecompileExtension(handle);","handlingStrategy":"type-guard","validationCode":"if (handle.Kind is not (HandleKind.TypeDefinition or HandleKind.MethodDefinition or HandleKind.PropertyDefinition))\n    throw new NotSupportedException($\"DecompileExtension only takes type/method/property handles, got {handle.Kind}\");\nvar tree = decompiler.DecompileExtension(handle);","typeGuard":"static bool IsDecompilableExtensionMember(EntityHandle h) =>\n    h.Kind is HandleKind.TypeDefinition or HandleKind.MethodDefinition or HandleKind.PropertyDefinition;","tryCatchPattern":null,"preventionTips":["Restrict extension-group iteration to methods and properties.","Never assume all HandleKind values are accepted by a given overload."],"tags":["decompilation","extensions","validation","type-guard"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}