{"record":{"id":"78279eee7374e8b7","repo":"dotnet/BenchmarkDotNet","slug":"string-cannot-be-empty-or-whitespace","errorCode":null,"errorMessage":"String cannot be empty or whitespace.","messagePattern":"String cannot be empty or whitespace\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Extensions/Polyfills/ArgumentExceptionExtensions.cs","lineNumber":31,"sourceCode":"            [CallerArgumentExpression(nameof(argument))] string? paramName = null)\n        {\n            if (argument is null)\n                throw new ArgumentNullException(paramName);\n\n            if (argument.Length == 0)\n                throw new ArgumentException(\"String cannot be empty.\", paramName);\n        }\n\n        public static void ThrowIfNullOrWhiteSpace([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)\n        {\n            if (argument is null)\n            {\n                throw new ArgumentNullException(paramName);\n            }\n\n            if (string.IsNullOrWhiteSpace(argument))\n            {\n                throw new ArgumentException(\"String cannot be empty or whitespace.\", paramName);\n            }\n        }\n    }\n}\n#endif\n","sourceCodeStart":13,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Extensions/Polyfills/ArgumentExceptionExtensions.cs#L13-L37","documentation":"Thrown by the ThrowIfNullOrWhiteSpace polyfill. After the null check, string.IsNullOrWhiteSpace(argument) returns true for whitespace-only input, raising ArgumentException (\"String cannot be empty or whitespace.\"). Stricter than ThrowIfNullOrEmpty: it also rejects \"   \", tabs, and other whitespace.","triggerScenarios":"An internal BenchmarkDotNet validation runs ThrowIfNullOrWhiteSpace on a string that is empty or consists only of whitespace characters (spaces, tabs, newlines).","commonSituations":"Whitespace leaked from trimmed user input, config files with blank-but-whitespace values, copy-paste of a path padded with spaces, or code that sets a label/name to \" \" by mistake.","solutions":["Trim and verify the value is non-empty before assigning it (string.IsNullOrWhiteSpace check).","Provide a real identifier/path/value instead of whitespace.","If whitespace is legitimately possible, sanitize it upstream so the validated API only ever sees trimmed content."],"exampleFix":"// before\nvar name = \"   \";\n\n// after\nvar name = \"MyBenchmark\";","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(value)) throw new InvalidOperationException(\"value must be non-empty/whitespace\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim user/config input and reject whitespace-only values at the boundary.","Prefer ThrowIfNullOrWhiteSpace-style guards in your own code for consistency.","Log the offending field name when validation fails to speed diagnosis."],"tags":["validation","argument","string","whitespace"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}