icsharpcode/ILSpy · error · NotSupportedException
Cannot compute an ID string for an entity that is not backed
Error message
Cannot compute an ID string for an entity that is not backed by metadata.
What it means
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.
Source
Thrown at ICSharpCode.Decompiler/Documentation/IdStringProvider.cs:186
}
return b.ToString();
}
/// <summary>
/// Gets the ID string (C# 4.0 spec, section A.3.1) for the specified entity.
/// </summary>
/// <remarks>
/// The ID string is computed from the entity's metadata; for specialized members
/// it describes the underlying member definition.
/// </remarks>
public static string GetIdString(this IEntity entity)
{
if (entity == null)
throw new ArgumentNullException(nameof(entity));
var module = entity.ParentModule?.MetadataFile;
if (module == null || entity.MetadataToken.IsNil)
throw new NotSupportedException("Cannot compute an ID string for an entity that is not backed by metadata.");
return GetIdString(module, entity.MetadataToken);
}
/// <summary>
/// Appends the fully qualified name of a type definition, handling nested types.
/// The metadata name already contains the `n arity suffix for generic types.
/// </summary>
static void AppendTypeDefinitionName(StringBuilder b, MetadataReader metadata, TypeDefinitionHandle handle)
{
var typeDef = metadata.GetTypeDefinition(handle);
var declaringType = typeDef.GetDeclaringType();
if (declaringType.IsNil)
{
var ns = metadata.GetString(typeDef.Namespace);
if (!string.IsNullOrEmpty(ns))
{
b.Append(ns);
View on GitHub (pinned to 60c08fcb74)
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.
Example fix
// before
string id = entity.GetIdString();
// after
IEntity def = entity is IMember m ? m.MemberDefinition : entity.GetDefinition() ?? entity;
string id = def.ParentModule?.MetadataFile != null && !def.MetadataToken.IsNil
? def.GetIdString()
: null; Defensive patterns
Strategy: validation
Validate before calling
if (entity == null || entity.ParentModule?.MetadataFile == null || entity.MetadataToken.IsNil)
return null;
return entity.GetIdString(); Type guard
static bool IsMetadataBacked(IEntity e) => e?.ParentModule?.MetadataFile != null && !e.MetadataToken.IsNil;
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The handle must not be nil.
- Unsupported handle kind: {handle.Kind}
- types contains null element
- Could not find type definition {fullTypeName} in type system
- definitions contains null element
AI-assisted analysis of icsharpcode/ILSpy@60c08fcb74 (2026-08-13).
Data as JSON: /api/errors/16704a042ce48a27.
Report an issue: GitHub.