dotnet/maui · error · ArgumentNullException
The parameter cannot be either null or empty or consist only
Error message
The parameter cannot be either null or empty or consist only of white space characters.
What it means
Verify.IsNeitherNullNorWhitespace throws ArgumentNullException when value is null. It is the whitespace-aware sibling of IsNeitherNullNorEmpty, used for parameters where a whitespace-only string is as invalid as empty. This branch handles the null case specifically.
Source
Thrown at src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs:89
/// <summary>
/// Ensure that an argument is neither null nor does it consist only of whitespace.
/// </summary>
/// <param name="value">The string 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")]
[SuppressMessage("Microsoft.Performance", "CA1820:TestForEmptyStringsUsingStringLength")]
[DebuggerStepThrough]
public static void IsNeitherNullNorWhitespace(string value, string name)
{
// catch caller errors, mixing up the parameters. Name should never be empty.
Assert.IsNeitherNullNorEmpty(name);
// Notice that ArgumentNullException and ArgumentException take the parameters in opposite order :P
const string errorMessage = "The parameter cannot be either null or empty or consist only of white space characters.";
if (null == value)
{
Assert.Fail();
throw new ArgumentNullException(name, errorMessage);
}
if ("" == value.Trim())
{
Assert.Fail();
throw new ArgumentException(errorMessage, name);
}
}
/// <summary>Verifies that an argument is not 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 IsNotDefault<T>(T obj, string name) where T : struct
{
if (default(T).Equals(obj))
{View on GitHub (pinned to f377ff1c5e)
Solutions
- Ensure the string is initialized to a non-null value before the call.
- Coalesce nulls to a valid default: value ?? defaultValue, or reject null explicitly at the boundary.
- Use string.IsNullOrWhiteSpace for the pre-check at the call site.
Example fix
// before window.SetTitle(title); // title may be null // after if (title == null) throw new ArgumentNullException(nameof(title)); window.SetTitle(title);
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check for null before calling the guarded API
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
SomeApi(value); Prevention
- Use string.IsNullOrWhiteSpace to catch null, empty, and whitespace in one check.
- Initialize optional string parameters to a real default rather than null.
- Coalesce null lookups before forwarding: value ?? throw new ArgumentNullException(...).
When it happens
Trigger: Calling a method guarded by Verify.IsNeitherNullNorWhitespace(value, name) and passing null. The null check is evaluated before the whitespace check, so null is reported as ArgumentNullException.
Common situations: Uninitialized string field forwarded to the API; optional parameter that defaulted to null but should have been required; lookup returned null and was passed through.
Related errors
- The parameter cannot be either null or empty.
- The parameter must not be the default value.
- The parameter must be null.
- The URI must be absolute.
- The integer value must be bounded with [{0}, {1})
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/348ce7296fc7ad6d.
Report an issue: GitHub.