dotnet/wpf · error · ArgumentException
SR.Verify_AreNotEqual
Error message
SR.Verify_AreNotEqual
What it means
Verify.AreNotEqual<T>(notExpected, actual, parameterName) throws ArgumentException(SR.Verify_AreNotEqual, parameterName) when actual equals the forbidden value. This branch handles notExpected == null: two nulls are considered equal, so actual must be non-null (and not 'equal' to null in the type's semantics). The formatted message includes the disallowed value.
Solutions
- Look at parameterName in the exception to find the argument; ensure it is not the forbidden value before the call.
- Add an explicit guard: if (Equals(actual, notExpected)) throw with a domain-specific message.
- Substitute a valid non-null value or default for the argument.
Example fix
// before Verify.AreNotEqual(null, value, nameof(value)); // value == null -> ArgumentException // after if (value == null) value = FallbackValue; Verify.AreNotEqual(null, value, nameof(value));
Defensive patterns
Strategy: validation
Validate before calling
if (actual is null)
throw new ArgumentNullException(nameof(actual), "null is not an allowed value here."); Type guard
bool IsAllowedValue<T>(T actual, T forbidden) where T : notnull => !forbidden.Equals(actual);
Try / catch
try
{
LibraryCall(actual);
}
catch (ArgumentException ex) when (ex.ParamName == "actual")
{
logger.LogError("Argument {Param} must not equal the forbidden value", ex.ParamName);
throw;
} Prevention
- Check arguments against forbidden sentinels before calling
- Avoid default(T) leaking into required parameters
- Initialize class fields to valid non-null values, not null
- Use nullable annotations to keep nulls out of non-nullable paths
When it happens
Trigger: Calling an API whose wrapper calls Verify.AreNotEqual(null, actual, name) while passing null (or a value whose Equals(null) is true) for that parameter.
Common situations: Passing null to parameters that must be non-null under value semantics; default(T) for a struct/class leaking in as the forbidden value; deserialized objects with null fields used as arguments.
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/9871e02789c59e06.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Verify.cs:96
throw new ArgumentException(message, name);
}
}
/// <summary>
/// Verifies two values are not equal to each other. Throws an ArgumentException if they are.
/// </summary>
/// <param name="actual">The actual value.</param>
/// <param name="notExpected">The value that 'actual' should not be.</param>
/// <param name="parameterName">The name to display for 'actual' in the exception if this test fails.</param>
/// <param name="message">The message to include in the ArgumentException.</param>
public static void AreNotEqual<T>(T actual, T notExpected, string parameterName, string message)
{
if (notExpected == null)
{
// Two nulls are considered equal, regardless of type semantics.
if (actual == null || actual.Equals(notExpected))
{
throw new ArgumentException(SR.Format(SR.Verify_AreNotEqual, notExpected), parameterName);
}
}
else if (notExpected.Equals(actual))
{
throw new ArgumentException(SR.Format(SR.Verify_AreNotEqual, notExpected), parameterName);
}
}
/// <summary>
/// Verifies the specified file exists. Throws an ArgumentException if it doesn't.
/// </summary>
/// <param name="filePath">The file path to check for existence.</param>
/// <param name="parameterName">Name of the parameter to include in the ArgumentException.</param>
/// <remarks>This method demands FileIOPermission(FileIOPermissionAccess.PathDiscovery)</remarks>
public static void FileExists(string filePath, string parameterName)
{
Verify.IsNeitherNullNorEmpty(filePath, parameterName);
View on GitHub (pinned to 81131a70a4)