{"record":{"id":"e43636c04c1988a6","repo":"dotnet/wpf","slug":"the-parameter-can-not-be-either-null-or-empty","errorCode":null,"errorMessage":"The parameter can not be either null or empty.","messagePattern":"The parameter can not be either null or empty\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs","lineNumber":62,"sourceCode":"        }\n\n        /// <summary>\n        /// Ensure that an argument is neither null nor empty.\n        /// </summary>\n        /// <param name=\"value\">The string to validate.</param>\n        /// <param name=\"name\">The name of the parameter that will be presented if an exception is thrown.</param>    \n        [SuppressMessage(\"Microsoft.Performance\", \"CA1820:TestForEmptyStringsUsingStringLength\")]\n        [DebuggerStepThrough]\n        public static void IsNeitherNullNorEmpty(string value, string name)\n        {\n            // catch caller errors, mixing up the parameters.  Name should never be empty.\n            Assert.IsNeitherNullNorEmpty(name);\n\n            // Notice that ArgumentNullException and ArgumentException take the parameters in opposite order :P\n            const string errorMessage = \"The parameter can not be either null or empty.\";\n            if (null == value)\n            {\n                throw new ArgumentNullException(name, errorMessage);\n            }\n            if (\"\" == value)\n            {\n                throw new ArgumentException(errorMessage, name);\n            }\n        }\n\n        /// <summary>\n        /// Ensure that an argument is neither null nor does it consist only of whitespace.\n        /// </summary>\n        /// <param name=\"value\">The string to validate.</param>\n        /// <param name=\"name\">The name of the parameter that will be presented if an exception is thrown.</param>        \n        [SuppressMessage(\"Microsoft.Performance\", \"CA1820:TestForEmptyStringsUsingStringLength\")]\n        [DebuggerStepThrough]\n        public static void IsNeitherNullNorWhitespace(string value, string name)\n        {\n            // catch caller errors, mixing up the parameters.  Name should never be empty.\n            Assert.IsNeitherNullNorEmpty(name);","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs#L44-L80","documentation":"Verify.IsNeitherNullNorEmpty validates that a string argument is neither null nor the empty string. It throws ArgumentNullException (null) or ArgumentException (empty) with the supplied parameter name. This is a preconditions helper used by WPF's internal Standard utility library to fail fast on bad string arguments.","triggerScenarios":"Calling any API that routes through Verify.IsNeitherNullNorEmpty (e.g. Verify.IsNeitherNullNorEmpty directly, or internal WPF helpers like HttpUtility/property-name checks) passing a null string: ArgumentNullException is thrown at Verify.cs:62; passing \"\": ArgumentException at Verify.cs:66.","commonSituations":"Passing string.Empty as a parameter name or resource key to WPF helper APIs; deserialization producing empty strings; refactoring that removed a default value previously supplied.","solutions":["Check String.IsNullOrEmpty(value) before the call and supply a valid non-empty string.","If the value legitimately can be empty, stop calling the Verify API with it or provide a sensible fallback string.","If it is a parameter name argument, make sure you actually pass nameof(param), not an empty literal.","Trace which argument is null/empty from the exception's ParamName property and fix at the source."],"exampleFix":"// before\nVerify.IsNeitherNullNorEmpty(name, nameof(name)); // name may be \"\"\n// after\nif (string.IsNullOrEmpty(name)) name = \"<unnamed>\";\nVerify.IsNeitherNullNorEmpty(name, nameof(name));","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(value))\n    throw new ArgumentException($\"{nameof(value)} must be non-null and non-empty\", nameof(value));\nVerify.IsNeitherNullNorEmpty(value, nameof(value));","typeGuard":"static bool IsNonEmptyString(string s) => !string.IsNullOrEmpty(s);","tryCatchPattern":"try {\n    Verify.IsNeitherNullNorEmpty(value, nameof(value));\n} catch (ArgumentNullException ex) {\n    log.Error($\"Parameter {ex.ParamName} was null\");\n} catch (ArgumentException ex) {\n    log.Error($\"Parameter {ex.ParamName} was empty\");\n}","preventionTips":["Run string.IsNullOrEmpty checks at API boundaries.","Always pass nameof(...) as the parameter name argument.","Normalize config/deserialized strings before use."],"tags":["argument-validation","wpf","null-check","string"],"backgroundTag":"null-argument","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"}