{"record":{"id":"16704a042ce48a27","repo":"icsharpcode/ILSpy","slug":"cannot-compute-an-id-string-for-an-entity-that-is","errorCode":null,"errorMessage":"Cannot compute an ID string for an entity that is not backed by metadata.","messagePattern":"Cannot compute an ID string for an entity that is not backed by metadata\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/Documentation/IdStringProvider.cs","lineNumber":186,"sourceCode":"\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\n\t\t\t\tthrow new NotSupportedException(\"Cannot compute an ID string for an entity that is not backed by metadata.\");\r\n\t\t\treturn GetIdString(module, entity.MetadataToken);\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t/// Appends the fully qualified name of a type definition, handling nested types.\r\n\t\t/// The metadata name already contains the `n arity suffix for generic types.\r\n\t\t/// </summary>\r\n\t\tstatic void AppendTypeDefinitionName(StringBuilder b, MetadataReader metadata, TypeDefinitionHandle handle)\r\n\t\t{\r\n\t\t\tvar typeDef = metadata.GetTypeDefinition(handle);\r\n\t\t\tvar declaringType = typeDef.GetDeclaringType();\r\n\r\n\t\t\tif (declaringType.IsNil)\r\n\t\t\t{\r\n\t\t\t\tvar ns = metadata.GetString(typeDef.Namespace);\r\n\t\t\t\tif (!string.IsNullOrEmpty(ns))\r\n\t\t\t\t{\r\n\t\t\t\t\tb.Append(ns);\r","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/Documentation/IdStringProvider.cs#L168-L204","documentation":"NotSupportedException thrown by the GetIdString(this IEntity) extension when the entity has no metadata backing: either entity.ParentModule or its MetadataFile is null, or entity.MetadataToken.IsNil. This happens for synthetic/computed entities that live in the type system but not in a PE file.","triggerScenarios":"Calling GetIdString on an ITypeParameter, an array/pointer/by-reference type, a ParameterizedType (instantiated generic), a specialized IMethod/IProperty returned by GetMethod/GetProperty, or a mock/dummy entity whose ParentModule is null.","commonSituations":"Iterating members of a type and computing IDs without distinguishing metadata-backed definitions from derived/synthetic members; calling GetIdString on a type-system construct built during analysis rather than read from metadata.","solutions":["Resolve to the underlying definition first (entity.GetDefinition() / member.MemberDefinition) and compute the ID on that.","Guard with `entity.ParentModule?.MetadataFile != null && !entity.MetadataToken.IsNil` before calling.","Skip entities whose MetadataToken is nil rather than passing them in."],"exampleFix":"// before\nstring id = entity.GetIdString();\n\n// after\nIEntity def = entity is IMember m ? m.MemberDefinition : entity.GetDefinition() ?? entity;\nstring id = def.ParentModule?.MetadataFile != null && !def.MetadataToken.IsNil\n    ? def.GetIdString()\n    : null;","handlingStrategy":"validation","validationCode":"if (entity == null || entity.ParentModule?.MetadataFile == null || entity.MetadataToken.IsNil)\n    return null;\nreturn entity.GetIdString();","typeGuard":"static bool IsMetadataBacked(IEntity e) => e?.ParentModule?.MetadataFile != null && !e.MetadataToken.IsNil;","tryCatchPattern":null,"preventionTips":["Resolve to a definition (GetDefinition/MemberDefinition) before computing IDs.","Treat type parameters, array/pointer/byref types, and instantiated generics as non-serializable to ID strings.","Guard ParentModule/MetadataFile and MetadataToken.IsNil before calling."],"tags":["id-string","metadata","not-supported","synthetic-entity"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}