{"record":{"id":"7c224d8f76f5fd4d","repo":"dotnet/BenchmarkDotNet","slug":"value-cannot-be-null-parameter-key","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'key')","messagePattern":"Value cannot be null\\. \\(Parameter 'key'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Jobs/EnvironmentVariable.cs","lineNumber":7,"sourceCode":"namespace BenchmarkDotNet.Jobs\n{\n    public class EnvironmentVariable : IEquatable<EnvironmentVariable>\n    {\n        public EnvironmentVariable(string key, string value)\n        {\n            Key = key ?? throw new ArgumentNullException(nameof(key));\n            Value = value ?? throw new ArgumentNullException(nameof(value));\n        }\n\n        public string Key { get; }\n\n        public string Value { get; }\n\n        // CharacteristicPresenters call ToString(), this is why we need this override\n        public override string ToString() => $\"{Key}={Value}\";\n\n        public bool Equals(EnvironmentVariable? other)\n        {\n            return string.Equals(Key, other?.Key) && string.Equals(Value, other?.Value);\n        }\n\n        public override bool Equals(object? obj)\n        {\n            if (ReferenceEquals(null, obj))","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Jobs/EnvironmentVariable.cs#L1-L25","documentation":"Thrown by the EnvironmentVariable constructor when the 'key' parameter is null. EnvironmentVariable represents a single key=value environment variable entry for a benchmark Job. The constructor enforces that both key and value are non-null because the variable is later serialized to the host process environment and displayed in reports (via ToString() which interpolates $\"{Key}={Value}\"). A null key would cause a NullReferenceException downstream.","triggerScenarios":"Constructing new EnvironmentVariable(null, \"someValue\") or passing a null key sourced from a dictionary lookup, config file, or dynamic code that did not supply a key string.","commonSituations":"Building environment variables from external configuration (JSON, YAML, command-line) where a key field is missing or whitespace. Also from LINQ projections over dictionaries where a null key leaks through.","solutions":["Validate the key before constructing: if (string.IsNullOrEmpty(key)) throw ... or skip the entry.","Ensure the data source (config file, dictionary) always has non-null keys by schema validation.","Use string.IsNullOrWhiteSpace check to also reject blank keys that are technically non-null but meaningless."],"exampleFix":"// before\nvar envVar = new EnvironmentVariable(configKey, configValue);\n\n// after\nif (string.IsNullOrWhiteSpace(configKey))\n    throw new InvalidOperationException(\"Environment variable key is missing from config.\");\nvar envVar = new EnvironmentVariable(configKey, configValue);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(key))\n    throw new InvalidOperationException(\"Environment variable key must be non-empty.\");\nvar envVar = new EnvironmentVariable(key, value);","typeGuard":"static bool IsValidEnvVarKey(string? key) => !string.IsNullOrWhiteSpace(key);","tryCatchPattern":null,"preventionTips":["Validate configuration keys at the boundary where external data enters (config loading).","Use nullable reference types to track where nulls can originate.","Build environment variables from a validated Dictionary<string, string> rather than ad-hoc construction."],"tags":["argument-validation","null-check","environment-variables"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}