icsharpcode/ILSpy · error · ArgumentNullException

v

Error message

v

What it means

Thrown by the two-argument ILVariableResolveResult constructor: this.Variable = v ?? throw new ArgumentNullException(nameof(v)). The message is just the parameter name 'v'. It is a programming-contract failure: the caller passed a null ILVariable when also supplying an explicit IType.

Source

Thrown at ICSharpCode.Decompiler/CSharp/Annotations.cs:257

			return node;
		}
	}

	/// <summary>
	/// Represents a reference to a local variable.
	/// </summary>
	public class ILVariableResolveResult : ResolveResult
	{
		public readonly ILVariable Variable;

		public ILVariableResolveResult(ILVariable v) : base(v.Type)
		{
			this.Variable = v;
		}

		public ILVariableResolveResult(ILVariable v, IType type) : base(type)
		{
			this.Variable = v ?? throw new ArgumentNullException(nameof(v));
		}
	}

	/// <summary>
	/// Annotates a <see cref="ForeachStatement"/> with the instructions for the GetEnumerator, MoveNext
	/// and get_Current calls.
	/// </summary>
	public class ForeachAnnotation
	{
		public readonly ILInstruction GetEnumeratorCall;
		public readonly ILInstruction MoveNextCall;
		public readonly ILInstruction GetCurrentCall;

		public ForeachAnnotation(ILInstruction getEnumeratorCall, ILInstruction moveNextCall,
			ILInstruction getCurrentCall)
		{
			GetEnumeratorCall = getEnumeratorCall;
			MoveNextCall = moveNextCall;

View on GitHub (pinned to 60c08fcb74)

Solutions

  1. Check the stack trace to find which transform produced the null ILVariable and report it as a decompiler bug.
  2. Update to a newer ILSpy/ILSpyX build; include the offending assembly in the report.
  3. If you call this constructor yourself, guard v before constructing.

Example fix

// before
var rr = new ILVariableResolveResult(variable, type); // variable may be null

// after
if (variable == null) throw new ArgumentNullException(nameof(variable));
var rr = new ILVariableResolveResult(variable, type);
Defensive patterns

Strategy: validation

Validate before calling

if (variable == null)
    throw new ArgumentNullException(nameof(variable));
var rr = new ILVariableResolveResult(variable, type);

Try / catch

try {
    var rr = new ILVariableResolveResult(variable, type);
} catch (ArgumentNullException ex) when (ex.ParamName == "v") {
    // upstream transform yielded a null variable; treat as decompiler bug
}

Prevention

When it happens

Trigger: Code constructs new ILVariableResolveResult(variable, type) where variable is null. This is internal decompiler-transform code, so a hit indicates a decompiler bug that resolved an ILVariable to null and still tried to build a resolve result.

Common situations: A decompiler transform/analyse pass could not allocate an ILVariable for a stack slot/parameter/local and passed null through.

Related errors


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