{"record":{"id":"870ef22b860b5481","repo":"HandyOrg/HandyControl","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/Shared/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":44,"sourceCode":"    {\n        if (value == null)\n        {\n            throw new ArgumentNullException(name, \"The parameter can not be either null or empty.\");\n        }\n        if (\"\" == value)\n        {\n            throw new ArgumentException(\"The parameter can not be either null or empty.\", name);\n        }\n    }\n\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1820:TestForEmptyStringsUsingStringLength\")]\n    [DebuggerStepThrough]\n    public static void IsNeitherNullNorWhitespace(string value, string name)\n    {\n        if (value == null)\n        {\n            throw new ArgumentNullException(name, \"The parameter can not be either null or empty or consist only of white space characters.\");\n        }\n        if (\"\" == value.Trim())\n        {\n            throw new ArgumentException(\"The parameter can not be either null or empty or consist only of white space characters.\", name);\n        }\n    }\n\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    [DebuggerStepThrough]\n    public static void IsNotDefault<T>(T obj, string name) where T : struct\n    {\n        T t = default(T);\n        if (t.Equals(obj))\n        {\n            throw new ArgumentException(\"The parameter must not be the default value.\", name);\n        }\n    }\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs#L26-L62","documentation":"Verify.IsNeitherNullNorWhitespace guards required string parameters: it throws ArgumentNullException for null and ArgumentException for strings that are empty or contain only whitespace (\"\" == value.Trim()).","triggerScenarios":"Calling Verify.IsNeitherNullNorWhitespace(null, name) — the null branch of the guard, typically from an API validating a required string like a path or name.","commonSituations":"Uninitialized string fields, missing registry/config values passed straight into shell APIs.","solutions":["Supply a non-null, non-whitespace string","Initialize defaults before invoking the API","Validate at the boundary with string.IsNullOrWhiteSpace for clearer messages","Catch ArgumentNullException to identify the offending parameter"],"exampleFix":"// before\nVerify.IsNeitherNullNorWhitespace(appUserModelId, \"appUserModelId\"); // NRE-style ArgumentNullException if null\n// after\nappUserModelId ??= \"MyApp.Default\";\nVerify.IsNeitherNullNorWhitespace(appUserModelId, \"appUserModelId\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(value))\n    throw new ArgumentException($\"'{name}' must be a non-blank string.\", name);","typeGuard":"static bool IsNonBlankString(string s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { Verify.IsNeitherNullNorWhitespace(value, name); }\ncatch (ArgumentNullException ex) { Log.Warn($\"Parameter {name} was null\", ex); }","preventionTips":["Coalesce null strings to defaults before validation","Check string.IsNullOrWhiteSpace at every external input boundary","Initialize required string fields at construction time"],"tags":["argument-validation","null","whitespace","guard"],"backgroundTag":"missing-required-argument","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}