{"record":{"id":"0dc9273342fec751","repo":"dotnet/wpf","slug":"the-parameter-can-not-be-either-null-or-empty-or-consist","errorCode":null,"errorMessage":"The parameter can not be either null or empty or consist only of white space characters.","messagePattern":"The parameter can not be either null or empty or consist only of white space characters\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs","lineNumber":86,"sourceCode":"        }\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);\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 or consist only of white space characters.\";\n            if (null == value)\n            {\n                throw new ArgumentNullException(name, errorMessage);\n            }\n            if (\"\" == value.Trim())\n            {\n                throw new ArgumentException(errorMessage, name);\n            }\n        }\n\n        /// <summary>Verifies that an argument is not null.</summary>\n        /// <typeparam name=\"T\">Type of the object to validate.  Must be a class.</typeparam>\n        /// <param name=\"obj\">The object to validate.</param>\n        /// <param name=\"name\">The name of the parameter that will be presented if an exception is thrown.</param>        \n        [DebuggerStepThrough]\n        public static void IsNotDefault<T>(T obj, string name) where T : struct\n        {\n            if (default(T).Equals(obj))\n            {\n                throw new ArgumentException(\"The parameter must not be the default value.\", name);\n            }","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs#L68-L104","documentation":"Verify.IsNeitherNullNorWhitespace validates that a string argument is not null, not empty, and not composed only of whitespace. A null value throws ArgumentNullException (Verify.cs:86) with the shared message about whitespace. Like the other Verify helpers it is a fail-fast precondition used across WPF's Standard utility layer.","triggerScenarios":"Calling Verify.IsNeitherNullNorWhitespace(value, name) with value == null — throws ArgumentNullException carrying the message 'The parameter can not be either null or empty or consist only of white space characters.'","commonSituations":"Config values or user input that were never set (null) being passed where a real string is required; interop paths passing unset names/keys.","solutions":["Guard with string.IsNullOrWhiteSpace(value) before the call and supply a valid string.","Provide a default/fallback value when the input is optional.","Fix the upstream producer so it does not emit null for this field.","Inspect ex.ParamName to identify which argument was null."],"exampleFix":"// before\nVerify.IsNeitherNullNorWhitespace(configValue, nameof(configValue)); // may be null\n// after\nif (string.IsNullOrWhiteSpace(configValue)) configValue = DefaultConfigValue;\nVerify.IsNeitherNullNorWhitespace(configValue, nameof(configValue));","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(value))\n    throw new ArgumentException($\"{nameof(value)} must be non-null, non-empty, non-whitespace\", nameof(value));\nVerify.IsNeitherNullNorWhitespace(value, nameof(value));","typeGuard":"static bool IsNonWhitespaceString(string s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try {\n    Verify.IsNeitherNullNorWhitespace(value, nameof(value));\n} catch (ArgumentNullException ex) {\n    log.Error($\"{ex.ParamName} was null\");\n}","preventionTips":["Use string.IsNullOrWhiteSpace (not just IsNullOrEmpty) for user-facing inputs.","Validate config at load time so nulls surface early.","Supply defaults for optional values."],"tags":["argument-validation","wpf","null-check"],"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"}