icsharpcode/ILSpy · error · ArgumentNullException
definitions
Error message
definitions
What it means
ArgumentNullException(nameof(definitions)) from Decompile(IEnumerable<EntityHandle>) when the definitions sequence is null. The public Decompile(params EntityHandle[]) overload forwards to this one, so passing null there lands here too.
Source
Thrown at ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs:1369
{
return SyntaxTreeToString(DecompileType(fullTypeName));
}
/// <summary>
/// Decompile the specified types and/or members.
/// </summary>
public SyntaxTree Decompile(params EntityHandle[] definitions)
{
return Decompile((IEnumerable<EntityHandle>)definitions);
}
/// <summary>
/// Decompile the specified types and/or members.
/// </summary>
public SyntaxTree Decompile(IEnumerable<EntityHandle> definitions)
{
if (definitions == null)
throw new ArgumentNullException(nameof(definitions));
syntaxTree = new SyntaxTree();
var namespaces = new HashSet<string>();
foreach (var entity in definitions)
{
if (entity.IsNil)
throw new ArgumentException("definitions contains null element");
RequiredNamespaceCollector.CollectNamespaces(entity, module, namespaces);
}
var decompileRun = CreateDecompileRun(namespaces);
bool first = true;
ITypeDefinition? parentTypeDef = null;
foreach (var entity in definitions)
{
switch (entity.Kind)
{
case HandleKind.TypeDefinition:
ITypeDefinition typeDef = module.GetDefinition((TypeDefinitionHandle)entity);
View on GitHub (pinned to 60c08fcb74)
Solutions
- Pass a non-null collection; use Array.Empty<EntityHandle>() instead of null for the empty case.
- Null-coalesce at the call site: decompiler.Decompile(handles ?? Array.Empty<EntityHandle>()).
Example fix
// before SyntaxTree tree = decompiler.Decompile(handles); // handles may be null // after SyntaxTree tree = decompiler.Decompile(handles ?? Array.Empty<EntityHandle>());
Defensive patterns
Strategy: validation
Validate before calling
var tree = decompiler.Decompile(handles ?? Array.Empty<EntityHandle>());
Prevention
- Return Array.Empty<EntityHandle>() instead of null from lookup helpers.
- Prefer the params overload with no args over passing an explicit null.
When it happens
Trigger: Calling Decompile((IEnumerable<EntityHandle>)null), Decompile((EntityHandle[])null), or passing a variable that is null because a preceding lookup returned no array.
Common situations: A LINQ/mapping step returns null on the empty case instead of an empty collection; an uninitialized EntityHandle[] field passed straight through.
Related errors
- types contains null element
- definitions contains null element
- handle
- HandleKind {handle.Kind} is not supported!
- Invalid BAML signature length.
AI-assisted analysis of icsharpcode/ILSpy@60c08fcb74 (2026-08-13).
Data as JSON: /api/errors/cfe4ab3087faf980.
Report an issue: GitHub.