dotnet/maui · error · ArgumentException
The parameter must be null.
Error message
The parameter must be null.
What it means
Verify.IsNull<T> (where T : class) throws ArgumentException when obj is NOT null. It is the inverse of the usual null check — it asserts that the argument must be null at this point. This is used for state-transition guards where a non-null value indicates the object is in the wrong lifecycle state.
Source
Thrown at src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs:139
if (null == obj)
{
Assert.Fail();
throw new ArgumentNullException(name);
}
}
/// <summary>Verifies that an argument is null.</summary>
/// <typeparam name="T">Type of the object to validate. Must be a class.</typeparam>
/// <param name="obj">The object to validate.</param>
/// <param name="name">The name of the parameter that will be presented if an exception is thrown.</param>
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void IsNull<T>(T obj, string name) where T : class
{
if (null != obj)
{
Assert.Fail();
throw new ArgumentException("The parameter must be null.", name);
}
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void PropertyIsNotNull<T>(T obj, string name) where T : class
{
if (null == obj)
{
Assert.Fail();
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The property {0} cannot be null at this time.", name));
}
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void PropertyIsNull<T>(T obj, string name) where T : class
{View on GitHub (pinned to f377ff1c5e)
Solutions
- Ensure the referenced object is set to null before calling the method that requires null.
- Check the lifecycle: if the object must be null, verify it has been reset/cleared first.
- Restructure to avoid double-initialization; guard the calling code against re-entry.
Example fix
// before window.Initialize(); // internal reference already set // after window.Reset(); // sets internal reference to null window.Initialize();
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check: the API requires the reference to be null
if (obj != null)
{
throw new ArgumentException("Reference must be null at this point.", nameof(obj));
}
SomeApi(obj); Prevention
- Reset references to null before calling lifecycle methods that require a clean state.
- Guard against re-entry / double-initialization at the call site.
- Document lifecycle ordering requirements for objects with must-be-null preconditions.
When it happens
Trigger: Calling a method guarded by Verify.IsNull(obj, name) when obj has already been assigned a non-null reference. The method expects the value to be unset/cleared at the time of the call.
Common situations: Calling an Initialize/Set method twice without first clearing the previous value; a dispose-then-reset path where the field was not nulled after disposal; lifecycle ordering where the caller advanced the object state out of order.
Related errors
- The parameter cannot be either null or empty.
- The parameter cannot be either null or empty or consist only
- The parameter must not be the default value.
- The property {0} must be null at this time.
- The URI must be absolute.
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/50f3492cb883bc3d.
Report an issue: GitHub.