dotnet/wpf · 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> validates that a value-type argument does not equal default(T) (e.g. 0, Guid.Empty, DateTime.MinValue). If obj equals the type's default, it throws ArgumentException with the parameter name. It prevents 'unset' struct values from flowing into APIs that require meaningful data.
Solutions
- Check obj.Equals(default(T)) before the call and initialize the struct properly.
- For Guids, ensure Guid.NewGuid() or a parsed value is assigned rather than relying on field initialization.
- Consider making the parameter nullable (T?) so 'unset' is explicit, or change the API contract.
- Read ex.ParamName to find which struct argument was default.
Example fix
// before
Guid id; // default Guid.Empty
Verify.IsNotDefault(id, nameof(id));
// after
Guid id = Guid.NewGuid();
if (id == Guid.Empty) throw new ArgumentException("id not initialized", nameof(id));
Verify.IsNotDefault(id, nameof(id)); Defensive patterns
Strategy: validation
Validate before calling
if (obj.Equals(default(T)))
throw new ArgumentException($"{nameof(obj)} must not be default(T)", nameof(obj));
Verify.IsNotDefault(obj, nameof(obj)); Type guard
static bool IsSet<T>(T v) where T : struct => !default(T).Equals(v);
Try / catch
try {
Verify.IsNotDefault(id, nameof(id));
} catch (ArgumentException ex) when (ex.ParamName == nameof(id)) {
id = GenerateNewId();
} Prevention
- Initialize struct fields at declaration or in constructors.
- Use Guid.NewGuid() rather than relying on field defaults for ids.
- Prefer nullable<T> or explicit HasValue flags when 'unset' is a legal state.
When it happens
Trigger: Calling Verify.IsNotDefault(obj, name) where obj == default(T), e.g. an uninitialized Guid.NewGuid field, a zero id, or a struct default-initialized by deserialization.
Common situations: Passing Guid.Empty as an identifier, zero handles/ids from failed lookups, structs default-constructed instead of initialized.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ' ' is not a valid value for ' '.
- ArgumentException(message, name)
- ArgumentNullException(name)
- ArgumentOutOfRangeException(authentication)
- ArgumentOutOfRangeException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/8d966acfbd08e12c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs:103
{
throw new ArgumentNullException(name, errorMessage);
}
if ("" == value.Trim())
{
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>
[DebuggerStepThrough]
public static void IsNotDefault<T>(T obj, string name) where T : struct
{
if (default(T).Equals(obj))
{
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>
[DebuggerStepThrough]
public static void IsNotNull<T>(T obj, string name) where T : class
{
if (null == obj)
{
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>View on GitHub (pinned to 81131a70a4)