icsharpcode/ILSpy · error · ArgumentNullException
handle
Error message
handle
What it means
ArgumentNullException(nameof(handle)) from DecompileExtension(EntityHandle) when handle.IsNil. EntityHandle is a struct, so this is the nil sentinel rather than a language null; the library surfaces it as ArgumentNullException to flag an unprovided argument.
Source
Thrown at ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs:1459
}
else if (parentTypeDef != null)
{
parentTypeDef = FindCommonDeclaringTypeDefinition(parentTypeDef, ev.DeclaringTypeDefinition);
}
break;
default:
throw new NotSupportedException(entity.Kind.ToString());
}
first = false;
}
RunTransforms(syntaxTree, decompileRun, parentTypeDef != null ? new SimpleTypeResolveContext(parentTypeDef) : new SimpleTypeResolveContext(typeSystem.MainModule));
return syntaxTree;
}
public SyntaxTree DecompileExtension(EntityHandle handle)
{
if (handle.IsNil)
throw new ArgumentNullException(nameof(handle));
syntaxTree = new SyntaxTree();
var namespaces = new HashSet<string>();
RequiredNamespaceCollector.CollectNamespaces(handle, module, namespaces);
var decompileRun = CreateDecompileRun(namespaces);
switch (handle.Kind)
{
case HandleKind.TypeDefinition:
ITypeDefinition typeDef = module.GetDefinition((TypeDefinitionHandle)handle);
syntaxTree.Members.Add(DoDecompile(typeDef, decompileRun, new SimpleTypeResolveContext(typeDef), asExtension: true));
RunTransforms(syntaxTree, decompileRun, new SimpleTypeResolveContext(typeDef));
break;
case HandleKind.MethodDefinition:
IMethod methodDef = module.GetDefinition((MethodDefinitionHandle)handle);
var extensionInfo = methodDef.ResolveExtensionInfo();
Debug.Assert(extensionInfo != null);
var memberInfo = extensionInfo.InfoOfExtensionMember((IMethod)methodDef.MemberDefinition).GetValueOrDefault();
var subst = new TypeParameterSubstitution(memberInfo.ExtensionGroupingTypeParameters, null);
View on GitHub (pinned to 60c08fcb74)
Solutions
- Check handle.IsNil before calling DecompileExtension.
- Resolve the extension-member handle from a known-good source (ResolveExtensionInfo) and bail if nil.
Example fix
// before var tree = decompiler.DecompileExtension(handle); // after if (handle.IsNil) throw new ArgumentNullException(nameof(handle)); var tree = decompiler.DecompileExtension(handle);
Defensive patterns
Strategy: validation
Validate before calling
if (handle.IsNil) throw new ArgumentNullException(nameof(handle)); var tree = decompiler.DecompileExtension(handle);
Prevention
- Resolve extension-member handles explicitly and bail on nil before calling.
- Keep a single validation helper for EntityHandle and reuse it at every entry point.
When it happens
Trigger: Calling DecompileExtension(default(EntityHandle)) or with a handle obtained from a lookup that returned nil.
Common situations: A selected extension-member handle that failed to resolve; passing a handle read from an uninitialized struct field.
Related errors
- types contains null element
- definitions
- definitions contains null element
- HandleKind {handle.Kind} is not supported!
- Extension member {extMember} is not supported for decompilat
AI-assisted analysis of icsharpcode/ILSpy@60c08fcb74 (2026-08-13).
Data as JSON: /api/errors/98a54e25e47feca2.
Report an issue: GitHub.