{"record":{"id":"789dbf5e1a09f8cc","repo":"icsharpcode/ILSpy","slug":"unsupported-handle-kind-handle-kind","errorCode":null,"errorMessage":"Unsupported handle kind: {handle.Kind}","messagePattern":"Unsupported handle kind: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/Documentation/IdStringProvider.cs","lineNumber":167,"sourceCode":"\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase HandleKind.MethodDefinition:\r\n\t\t\t\t\tb.Append(\"M:\");\r\n\t\t\t\t\tAppendMethodIdString(b, metadata, (MethodDefinitionHandle)handle, cppCliDialect);\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase HandleKind.PropertyDefinition:\r\n\t\t\t\t\tb.Append(\"P:\");\r\n\t\t\t\t\tAppendPropertyIdString(b, metadata, (PropertyDefinitionHandle)handle, cppCliDialect);\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tcase HandleKind.EventDefinition:\r\n\t\t\t\t\tb.Append(\"E:\");\r\n\t\t\t\t\tAppendEventIdString(b, metadata, (EventDefinitionHandle)handle);\r\n\t\t\t\t\tbreak;\r\n\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new ArgumentException($\"Unsupported handle kind: {handle.Kind}\", nameof(handle));\r\n\t\t\t}\r\n\r\n\t\t\treturn b.ToString();\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t/// Gets the ID string (C# 4.0 spec, section A.3.1) for the specified entity.\r\n\t\t/// </summary>\r\n\t\t/// <remarks>\r\n\t\t/// The ID string is computed from the entity's metadata; for specialized members\r\n\t\t/// it describes the underlying member definition.\r\n\t\t/// </remarks>\r\n\t\tpublic static string GetIdString(this IEntity entity)\r\n\t\t{\r\n\t\t\tif (entity == null)\r\n\t\t\t\tthrow new ArgumentNullException(nameof(entity));\r\n\t\t\tvar module = entity.ParentModule?.MetadataFile;\r\n\t\t\tif (module == null || entity.MetadataToken.IsNil)\r","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/Documentation/IdStringProvider.cs#L149-L185","documentation":"ArgumentException thrown by GetIdString's default switch case when handle.Kind is not one of the definition kinds it can render: TypeDefinition, FieldDefinition, MethodDefinition, PropertyDefinition, EventDefinition. The C# doc-comment ID format is defined only for these definition handles; references and specs (TypeReference, TypeSpec, MethodSpec, MemberReference, GenericParameter, AssemblyReference, etc.) are rejected.","triggerScenarios":"Passing a TypeReference, TypeSpec, MethodSpec, MemberReference, GenericParameter, or AssemblyReference handle to GetIdString(module, handle).","commonSituations":"Feeding a resolved-but-not-definition handle (e.g. a MethodSpec for an instantiated generic method, or a TypeReference from a signature) into GetIdString instead of resolving it to its definition handle first.","solutions":["Resolve the handle to its definition before computing the ID string (e.g. follow a MethodSpec to its MethodDefinition, a TypeSpec/TypeReference to its TypeDefinition).","Guard on handle.Kind: only call GetIdString for HandleKind.TypeDefinition/FieldDefinition/MethodDefinition/PropertyDefinition/EventDefinition.","Use GetIdString(this IEntity entity) on the resolved entity, which yields the underlying definition's ID."],"exampleFix":"// before\nvar id = IdStringProvider.GetIdString(module, methodSpecHandle);\n\n// after\nvar methodSpec = metadata.GetMethodSpecification(methodSpecHandle);\nvar defHandle = methodSpec.Method;\nvar id = IdStringProvider.GetIdString(module, defHandle);","handlingStrategy":"validation","validationCode":"static readonly HashSet<HandleKind> IdKinds = new() {\n    HandleKind.TypeDefinition, HandleKind.FieldDefinition,\n    HandleKind.MethodDefinition, HandleKind.PropertyDefinition, HandleKind.EventDefinition };\n\nif (!IdKinds.Contains(handle.Kind)) return null;\nvar id = IdStringProvider.GetIdString(module, handle);","typeGuard":"static bool HasIdStringHandle(EntityHandle h) => h.Kind is HandleKind.TypeDefinition or HandleKind.FieldDefinition or HandleKind.MethodDefinition or HandleKind.PropertyDefinition or HandleKind.EventDefinition;","tryCatchPattern":null,"preventionTips":["Resolve references/specs to their definition handle before computing an ID string.","Whitelist the five definition handle kinds before calling GetIdString.","Use the entity-based overload so the definition is selected for you."],"tags":["id-string","metadata","handle-kind","argument"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}