{"record":{"id":"348ce7296fc7ad6d","repo":"dotnet/maui","slug":"the-parameter-cannot-be-either-null-or-empty-or-co","errorCode":null,"errorMessage":"The parameter cannot be either null or empty or consist only of white space characters.","messagePattern":"The parameter cannot be either null or empty or consist only of white space characters\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":89,"sourceCode":"\t\t/// <summary>\n\t\t/// Ensure that an argument is neither null nor does it consist only of whitespace.\n\t\t/// </summary>\n\t\t/// <param name=\"value\">The string to validate.</param>\n\t\t/// <param name=\"name\">The name of the parameter that will be presented if an exception is thrown.</param>\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1820:TestForEmptyStringsUsingStringLength\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void IsNeitherNullNorWhitespace(string value, string name)\n\t\t{\n\t\t\t// catch caller errors, mixing up the parameters.  Name should never be empty.\n\t\t\tAssert.IsNeitherNullNorEmpty(name);\n\n\t\t\t// Notice that ArgumentNullException and ArgumentException take the parameters in opposite order :P\n\t\t\tconst string errorMessage = \"The parameter cannot be either null or empty or consist only of white space characters.\";\n\t\t\tif (null == value)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentNullException(name, errorMessage);\n\t\t\t}\n\t\t\tif (\"\" == value.Trim())\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(errorMessage, name);\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>Verifies that an argument is not null.</summary>\n\t\t/// <typeparam name=\"T\">Type of the object to validate.  Must be a class.</typeparam>\n\t\t/// <param name=\"obj\">The object to validate.</param>\n\t\t/// <param name=\"name\">The name of the parameter that will be presented if an exception is thrown.</param>\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void IsNotDefault<T>(T obj, string name) where T : struct\n\t\t{\n\t\t\tif (default(T).Equals(obj))\n\t\t\t{","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs#L71-L107","documentation":"Verify.IsNeitherNullNorWhitespace throws ArgumentNullException when value is null. It is the whitespace-aware sibling of IsNeitherNullNorEmpty, used for parameters where a whitespace-only string is as invalid as empty. This branch handles the null case specifically.","triggerScenarios":"Calling a method guarded by Verify.IsNeitherNullNorWhitespace(value, name) and passing null. The null check is evaluated before the whitespace check, so null is reported as ArgumentNullException.","commonSituations":"Uninitialized string field forwarded to the API; optional parameter that defaulted to null but should have been required; lookup returned null and was passed through.","solutions":["Ensure the string is initialized to a non-null value before the call.","Coalesce nulls to a valid default: value ?? defaultValue, or reject null explicitly at the boundary.","Use string.IsNullOrWhiteSpace for the pre-check at the call site."],"exampleFix":"// before\nwindow.SetTitle(title); // title may be null\n\n// after\nif (title == null) throw new ArgumentNullException(nameof(title));\nwindow.SetTitle(title);","handlingStrategy":"validation","validationCode":"// Pre-check for null before calling the guarded API\nif (value == null)\n{\n    throw new ArgumentNullException(nameof(value));\n}\nSomeApi(value);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use string.IsNullOrWhiteSpace to catch null, empty, and whitespace in one check.","Initialize optional string parameters to a real default rather than null.","Coalesce null lookups before forwarding: value ?? throw new ArgumentNullException(...)."],"tags":["validation","argument","null-check","whitespace","verify"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}