{"record":{"id":"bdeecad419b7d5ff","repo":"microsoft/aspire","slug":"must-not-be-null-or-whitespace-guard","errorCode":null,"errorMessage":"Must not be null or whitespace","messagePattern":"Must not be null or whitespace","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs","lineNumber":109,"sourceCode":"        }\n#pragma warning restore CS8777 // Parameter must have a non-null value when exiting.\n\n        /// <summary>\n        /// Throw an exception if the value is null or whitespace.\n        /// </summary>\n        /// <param name=\"value\">The value to check.</param>\n        /// <param name=\"paramName\">The parameter name to use in the thrown exception.</param>\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static void ThrowIfNullOrWhitespace([NotNull] string? value, [CallerArgumentExpression(nameof(value))] string? paramName = null)\n#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.\n        {\n#if NET\n            ArgumentException.ThrowIfNullOrWhiteSpace(value, paramName);\n#else\n            if (string.IsNullOrWhiteSpace(value))\n            {\n                throw new ArgumentException(\"Must not be null or whitespace\", paramName);\n            }\n#endif\n        }\n#pragma warning restore CS8777 // Parameter must have a non-null value when exiting.\n\n        /// <summary>\n        /// Throw an exception if the value is zero.\n        /// </summary>\n        /// <param name=\"value\">The value to check.</param>\n        /// <param name=\"message\">The message to use in the thrown exception.</param>\n        /// <param name=\"paramName\">The parameter name to use in the thrown exception.</param>\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static void ThrowIfZero(int value, string message = \"Must not be zero\", [CallerArgumentExpression(nameof(value))] string? paramName = null)\n        {\n#if NET\n            ArgumentOutOfRangeException.ThrowIfZero(value, paramName);\n#else","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs#L91-L127","documentation":"Thrown by Guard.ThrowIfNullOrWhitespace in the vendored StackExchangeRedis instrumentation's Guard helper when a required string parameter is null, empty, or whitespace-only. On .NET targets it delegates to ArgumentException.ThrowIfNullOrWhiteSpace; otherwise it throws ArgumentException with \"Must not be null or whitespace\". Stricter than 2048: blank strings like \"   \" also fail.","triggerScenarios":"Passing a null, empty, or whitespace-only string to any API guarded by ThrowIfNullOrWhitespace, e.g. a name, key, or identifier derived from config or user input that contained only spaces.","commonSituations":"Config entries with placeholder spaces; trim operations that emptied the string; templates where a required field was left as blank/whitespace filler.","solutions":["Trim and validate the value with string.IsNullOrWhiteSpace before passing it; provide a real value.","Correct the upstream configuration or input source so the field cannot be blank.","Add whitespace validation at your own boundary to fail with a more descriptive message."],"exampleFix":"// before\nUseKey(settings[\"Key\"] ?? \"   \");\n\n// after\nvar key = settings[\"Key\"]?.Trim();\nArgumentException.ThrowIfNullOrWhiteSpace(key);\nUseKey(key);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(name))\n{\n    throw new ArgumentException(\"Must not be null or whitespace\", nameof(name));\n}","typeGuard":"static bool IsValidName([NotNullWhen(true)] string? name) => !string.IsNullOrWhiteSpace(name);","tryCatchPattern":"try\n{\n    instrumented.SetName(name);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"name\")\n{\n    logger.LogError(ex, \"'name' is required and must not be blank\");\n}","preventionTips":["Trim inputs before validating required fields","Add startup validation for all required string settings","Reject blank placeholders in templates and config files early"],"tags":["argument-empty","whitespace","validation","opentelemetry","redis"],"backgroundTag":"empty-required-field","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}