icsharpcode/ILSpy · error · ArgumentOutOfRangeException

Unexpected member type

Error message

Unexpected member type

What it means

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.

Source

Thrown at ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs:2019

						}
						entityDecl = DoDecompile(method, decompileRun, decompilationContext.WithCurrentMember(method), null);
						entityMap.Add(method, entityDecl);
						foreach (var helper in AddInterfaceImplHelpers(entityDecl, method, typeSystemAstBuilder))
						{
							entityMap.Add(method, helper);
						}
						break;
					case IEvent @event:
						entityDecl = DoDecompile(@event, decompileRun, decompilationContext.WithCurrentMember(@event));
						entityMap.Add(@event, entityDecl);
						break;
					case ITypeDefinition type:
						entityDecl = DoDecompile(type, decompileRun, decompilationContext.WithCurrentTypeDefinition(type));
						SetNewModifier(entityDecl);
						entityMap.Add(type, entityDecl);
						break;
					default:
						throw new ArgumentOutOfRangeException("Unexpected member type");
				}

				EnqueueReferencedMembers(entityDecl);

				void EnqueueReferencedMembers(EntityDeclaration decl)
				{
					foreach (var node in decl.Descendants)
					{
						var rr = node.GetResolveResult();
						if (rr is MemberResolveResult mrr
							&& mrr.Member.DeclaringTypeDefinition == typeDef
							&& !(mrr.Member is IMethod { IsLocalFunction: true }))
						{
							workList.Enqueue(mrr.Member);
						}
						else if (rr is TypeResolveResult trr
							&& trr.Type.GetDefinition()?.DeclaringTypeDefinition == typeDef)
						{

View on GitHub (pinned to 60c08fcb74)

Solutions

  1. Catch ArgumentOutOfRangeException (or the wrapping DecompilerException) around the type decompile to keep the batch alive.
  2. Inspect the entity's runtime type and report it as an ILSpy issue with the assembly and the offending type token.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    var tree = decompiler.Decompile(typeHandle);
} catch (DecompilerException ex) when (ex.InnerException is ArgumentOutOfRangeException) {
    logger.Error("Internal: unrecognized member kind in {Entity}", ex.DecompiledEntity?.FullName);
}

Prevention

When it happens

Trigger: 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.

Common situations: Plugging a custom metadata provider; very rare with real PE files, where it usually indicates an ILSpy bug.

Related errors


AI-assisted analysis of icsharpcode/ILSpy@60c08fcb74 (2026-08-13). Data as JSON: /api/errors/dd00c81f88af7cdc. Report an issue: GitHub.