{"record":{"id":"3be6fdd8b4e36d25","repo":"HandyOrg/HandyControl","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/Shared/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":29,"sourceCode":"{\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    [DebuggerStepThrough]\n    public static void IsApartmentState(ApartmentState requiredState, string message)\n    {\n        if (Thread.CurrentThread.GetApartmentState() != requiredState)\n        {\n            throw new InvalidOperationException(message);\n        }\n    }\n\n    [DebuggerStepThrough]\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1820:TestForEmptyStringsUsingStringLength\")]\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    public static void IsNeitherNullNorEmpty(string value, string name)\n    {\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        {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs#L11-L47","documentation":"Validation helper guard: Verify.IsNeitherNullNullOrEmpty throws when the string argument it is asked to check is null, empty, or whitespace-only. It fires at argument-check time in callers (typically Getters/Setters in the Standard shell library) — the input at fault is the parameter passed to the guarded API, commonly a device/context name or resource string that was never supplied.","triggerScenarios":"Calling Verify.IsNeitherNullNorEmpty(null, \"name\") or with \"\" as the value — from any API whose first act is validating a required string parameter via this helper.","commonSituations":"Passing unset configuration strings, empty command-line/registry values, or unassigned properties into shell/jumplist APIs.","solutions":["Supply a non-empty string for the parameter","Initialize the value before the call (default or from valid config)","Add caller-side validation with a clearer error message","Catch ArgumentNullException/ArgumentException to surface which parameter was invalid"],"exampleFix":"// before\nVerify.IsNeitherNullNorEmpty(config.Name, \"Name\"); // throws when Name is \"\"\n// after\nif (string.IsNullOrEmpty(config.Name)) config.Name = \"Default\";\nVerify.IsNeitherNullNorEmpty(config.Name, \"Name\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(value))\n    throw new ArgumentException($\"'{name}' must be a non-empty string.\", name);","typeGuard":"static bool IsNonEmptyString(string s) => !string.IsNullOrEmpty(s);","tryCatchPattern":"try { Verify.IsNeitherNullNorEmpty(value, name); }\ncatch (ArgumentNullException ex) { HandleMissing(name, ex); }\ncatch (ArgumentException ex) { HandleEmpty(name, ex); }","preventionTips":["Validate string inputs with string.IsNullOrEmpty at the API boundary","Default empty config values to sensible constants","Distinguish null vs empty in your own error messages"],"tags":["argument-validation","null","empty-string","guard"],"backgroundTag":"empty-required-field","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"}