{"record":{"id":"5825c779b5f989c2","repo":"dotnet/maui","slug":"the-parameter-cannot-be-either-null-or-empty","errorCode":null,"errorMessage":"The parameter cannot be either null or empty.","messagePattern":"The parameter cannot be either null or empty\\.","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":62,"sourceCode":"\t\t/// <summary>\n\t\t/// Ensure that an argument is neither null nor empty.\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 IsNeitherNullNorEmpty(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.\";\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)\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>\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{","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs#L44-L80","documentation":"Verify.IsNeitherNullNorEmpty is an argument-validation helper that throws ArgumentNullException when the supplied string value is null. It is intended as a guard clause at the top of public methods. The paramName is taken from the 'name' argument so the exception points at the offending parameter.","triggerScenarios":"Calling a public method whose first lines run Verify.IsNeitherNullNorEmpty(value, nameof(value)) and passing null for value. The Assert.Fail() that precedes the throw only fires in debug builds; the exception always throws.","commonSituations":"Caller omitted a required string argument; a property backing field was never initialized; a config or path string came back null from a lookup and was forwarded without a null check.","solutions":["Pass a non-null, non-empty string — initialize the value before calling the API.","Guard at the call site with a null check and a meaningful default or early return.","Use nameof(parameter) so the exception message names the correct parameter."],"exampleFix":"// before\nDoWork(path); // path may be null\n\n// after\nif (path == null) throw new ArgumentNullException(nameof(path));\nDoWork(path);","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":["Initialize all string fields and parameters before forwarding them to guarded APIs.","Use nullable reference types (string?) to surface null-safety at compile time.","Apply nameof(parameter) so exceptions name the correct argument."],"tags":["validation","argument","null-check","verify"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}