{"record":{"id":"142774b6b280c98e","repo":"dotnet/wpf","slug":"argumentexception-message-name","errorCode":null,"errorMessage":"ArgumentException(message, name)","messagePattern":"ArgumentException\\(message, name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Verify.cs","lineNumber":78,"sourceCode":"        public static void IsNotNull<T>(T obj, string name) where T : class\n        {\n            if (obj == null)\n            {\n                throw new ArgumentNullException(name);\n            }\n        }\n\n        /// <summary>\n        /// Verifies the specified expression is true.  Throws an ArgumentException if it's not.\n        /// </summary>\n        /// <param name=\"expression\">The expression to be verified as true.</param>\n        /// <param name=\"name\">Name of the parameter to include in the ArgumentException.</param>\n        /// <param name=\"message\">The message to include in the ArgumentException.</param>\n        public static void IsTrue(bool expression, string name, string message)\n        {\n            if (!expression)\n            {\n                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);","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Verify.cs#L60-L96","documentation":"Verify.IsTrue(bool expression, string name, string message) throws ArgumentException(message, name) when the supplied expression is false. It is a generic precondition helper: the caller supplies both the parameter name and the explanatory message, so the exception text describes exactly which condition was violated. Unlike Debug.Assert it throws in release builds.","triggerScenarios":"Any call path in WindowsBase that calls Verify.IsTrue and whose precondition fails - e.g. a flag/parameter combination the API forbids, or an object in the wrong state at the call site.","commonSituations":"Passing mutually exclusive options; calling an API before initialization so an internal boolean precondition is false; misuse of an internal/helper API not intended for public callers.","solutions":["Read the exception's Message and ParamName to learn which condition failed; correct that condition at the call site.","Check the API's documentation/usage for the required parameter combination or preconditions.","If the condition depends on initialization order, ensure the object is fully initialized before invoking the API.","Wrap in try/catch only when the failure is an expected, recoverable misuse in your own orchestration code."],"exampleFix":"// before\ncollection.VerifyIndex(i); // Verify.IsTrue(i >= 0, \"index\", \"index must be >= 0\") fails for i = -1\n// after\nif (i < 0) throw new ArgumentOutOfRangeException(nameof(i));\ncollection.VerifyIndex(i);","handlingStrategy":"validation","validationCode":"if (!precondition)\n    throw new ArgumentException($\"{nameof(arg)} does not satisfy the required precondition.\", nameof(arg));","typeGuard":"bool MeetsPrecondition(T arg) => /* mirror of the API's required condition */ arg is not null && arg.IsValid;","tryCatchPattern":"try\n{\n    LibraryCall(arg);\n}\ncatch (ArgumentException ex)\n{\n    logger.LogError(\"Precondition failed for {Param}: {Message}\", ex.ParamName, ex.Message);\n    throw;\n}","preventionTips":["Read the API docs for required preconditions and encode them in your own guards","Validate parameter combinations (mutually exclusive flags) before calling","Ensure initialization order: objects fully constructed before use","Don't call internal/helper APIs not designed for external callers"],"tags":["argument-validation","precondition","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"}