icsharpcode/ILSpy · error · ArgumentNullException

types

Error message

types

What it means

Thrown by CSharpDecompiler.DecompileTypes(IEnumerable<TypeDefinitionHandle> types): if types == null -> throw new ArgumentNullException(nameof(types)). The message is the parameter name 'types'. DecompileTypes needs a (possibly empty) sequence of handles to decompile.

Source

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

		/// <summary>
		/// Decompiles the whole module into a single string.
		/// </summary>
		public string DecompileWholeModuleAsString()
		{
			return SyntaxTreeToString(DecompileWholeModuleAsSingleFile());
		}

		/// <summary>
		/// Decompile the given types.
		/// </summary>
		/// <remarks>
		/// Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definitions.
		/// </remarks>
		public SyntaxTree DecompileTypes(IEnumerable<TypeDefinitionHandle> types)
		{
			if (types == null)
				throw new ArgumentNullException(nameof(types));
			var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainModule);
			syntaxTree = new SyntaxTree();
			var namespaces = new HashSet<string>();
			foreach (var type in types)
			{
				CancellationToken.ThrowIfCancellationRequested();
				if (type.IsNil)
					throw new ArgumentException("types contains null element");
				RequiredNamespaceCollector.CollectNamespaces(type, module, namespaces);
			}

			var decompileRun = CreateDecompileRun(namespaces);
			DoDecompileTypes(types, decompileRun, decompilationContext, syntaxTree);
			RunTransforms(syntaxTree, decompileRun, decompilationContext);
			return syntaxTree;
		}

		/// <summary>

View on GitHub (pinned to 60c08fcb74)

Solutions

  1. Pass a non-null IEnumerable<TypeDefinitionHandle> (use Enumerable.Empty<TypeDefinitionHandle>() for 'none').
  2. Null-check the sequence at the call site.

Example fix

// before
var tree = decompiler.DecompileTypes(maybeNullHandles);

// after
var handles = maybeNullHandles ?? Enumerable.Empty<TypeDefinitionHandle>();
var tree = decompiler.DecompileTypes(handles);
Defensive patterns

Strategy: validation

Validate before calling

var handles = types ?? Enumerable.Empty<TypeDefinitionHandle>();
var tree = decompiler.DecompileTypes(handles);

Try / catch

var tree = decompiler.DecompileTypes(
    types ?? throw new ArgumentNullException(nameof(types)));

Prevention

When it happens

Trigger: Calling DecompileTypes(null), or passing a LINQ expression that yielded null instead of an empty enumerable.

Common situations: Caller built the handle list conditionally and returned null; an upstream query returned null.

Related errors


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