{"record":{"id":"9871e02789c59e06","repo":"dotnet/wpf","slug":"sr-verify-arenotequal","errorCode":null,"errorMessage":"SR.Verify_AreNotEqual","messagePattern":"SR\\.Verify_AreNotEqual","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Verify.cs","lineNumber":96,"sourceCode":"                throw new ArgumentException(message, name);\n            }\n        }\n\n        /// <summary>\n        /// Verifies two values are not equal to each other.  Throws an ArgumentException if they are.\n        /// </summary>\n        /// <param name=\"actual\">The actual value.</param>\n        /// <param name=\"notExpected\">The value that 'actual' should not be.</param>\n        /// <param name=\"parameterName\">The name to display for 'actual' in the exception if this test fails.</param>\n        /// <param name=\"message\">The message to include in the ArgumentException.</param>\n        public static void AreNotEqual<T>(T actual, T notExpected, string parameterName, string message)\n        {\n            if (notExpected == null)\n            {\n                // Two nulls are considered equal, regardless of type semantics.\n                if (actual == null || actual.Equals(notExpected))\n                {\n                    throw new ArgumentException(SR.Format(SR.Verify_AreNotEqual, notExpected), parameterName);\n                }\n            }\n            else if (notExpected.Equals(actual))\n            {\n                throw new ArgumentException(SR.Format(SR.Verify_AreNotEqual, notExpected), parameterName);\n            }\n        }\n\n        /// <summary>\n        /// Verifies the specified file exists.  Throws an ArgumentException if it doesn't.\n        /// </summary>\n        /// <param name=\"filePath\">The file path to check for existence.</param>\n        /// <param name=\"parameterName\">Name of the parameter to include in the ArgumentException.</param>\n        /// <remarks>This method demands FileIOPermission(FileIOPermissionAccess.PathDiscovery)</remarks>\n        public static void FileExists(string filePath, string parameterName)\n        {\n            Verify.IsNeitherNullNorEmpty(filePath, parameterName);\n","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Verify.cs#L78-L114","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nVerify.AreNotEqual(null, value, nameof(value)); // value == null -> ArgumentException\n// after\nif (value == null) value = FallbackValue;\nVerify.AreNotEqual(null, value, nameof(value));","handlingStrategy":"validation","validationCode":"if (actual is null)\n    throw new ArgumentNullException(nameof(actual), \"null is not an allowed value here.\");","typeGuard":"bool IsAllowedValue<T>(T actual, T forbidden) where T : notnull => !forbidden.Equals(actual);","tryCatchPattern":"try\n{\n    LibraryCall(actual);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"actual\")\n{\n    logger.LogError(\"Argument {Param} must not equal the forbidden value\", ex.ParamName);\n    throw;\n}","preventionTips":["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"],"tags":["argument-validation","equality","wpf"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}