dotnet/maui · error · ArgumentException
The parameter must not be the default value.
Error message
The parameter must not be the default value.
What it means
Verify.IsNotDefault<T> (where T : struct) throws ArgumentException when obj.Equals(default(T)) — i.e. the value is the zero/default representation of its value type. This guard is used to reject uninitialized structs (Guid.Empty, default IntPtr, IntPtr.Zero, etc.).
Source
Thrown at src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs:109
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))
{
Assert.Fail();
throw new ArgumentException("The parameter must not be the default value.", 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 IsNotNull<T>(T obj, string name) where T : class
{
if (null == obj)
{
Assert.Fail();
throw new ArgumentNullException(name);
}
}
View on GitHub (pinned to f377ff1c5e)
Solutions
- Initialize the struct to a meaningful non-default value before the call.
- If the value comes from a lookup, check for default(T) before forwarding (e.g. if (handle == IntPtr.Zero)).
- Use nullable wrappers (Guid?) when absence is a valid state.
Example fix
// before
Register(id); // id may be Guid.Empty
// after
if (id == Guid.Empty)
{
throw new ArgumentException("A valid id is required.", nameof(id));
}
Register(id); Defensive patterns
Strategy: validation
Validate before calling
// Pre-check for default value-type before calling the guarded API
if (value.Equals(default(T)))
{
throw new ArgumentException($"Value must not be the default {typeof(T).Name}.", nameof(value));
}
SomeApi(value); Prevention
- Check value-type defaults (Guid.Empty, IntPtr.Zero, etc.) before forwarding to guarded APIs.
- Use nullable wrappers (Guid?) when absence is a legitimate state.
- Initialize struct fields to meaningful values in constructors.
When it happens
Trigger: Calling a method guarded by Verify.IsNotDefault(value, name) where value is default(T) for its struct type — e.g. Guid.Empty, new IntPtr(0), default(DateTime), or a zero-valued handle struct.
Common situations: A Guid was never assigned and left as Guid.Empty; an IntPtr handle was not obtained from the OS; a value-type enum defaulted to 0 which is not a valid member; a struct field was declared but never initialized.
Related errors
- The parameter cannot be either null or empty.
- The parameter cannot be either null or empty or consist only
- 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/ecf14b3e495a784b.
Report an issue: GitHub.