{"record":{"id":"4e4cf08e1684d6d9","repo":"dotnet/BenchmarkDotNet","slug":"value-cannot-be-null-parameter-value","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'value')","messagePattern":"Value cannot be null\\. \\(Parameter 'value'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Jobs/EnvironmentVariable.cs","lineNumber":8,"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))\n                return false;","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Jobs/EnvironmentVariable.cs#L1-L26","documentation":"Thrown by the EnvironmentVariable constructor when the 'value' parameter is null. The constructor requires both key and value to be non-null because the value is set on the host process environment and rendered in benchmark reports. A null value would cause a NullReferenceException when the variable is passed to the process or formatted via ToString().","triggerScenarios":"Constructing new EnvironmentVariable(\"KEY\", null) or passing a null value that originated from a missing dictionary entry, nullable config field, or a LINQ Select that produced null.","commonSituations":"Loading environment variables from configuration where some entries have keys but missing/null values. Also occurs when conditionally setting variables and forgetting to provide the value branch.","solutions":["Coalesce null values to empty string if semantically acceptable: value ?? string.Empty.","Filter out entries with null values before constructing EnvironmentVariable objects.","Validate the data source ensures every key has a corresponding non-null value."],"exampleFix":"// before\nvar envVar = new EnvironmentVariable(entry.Key, entry.Value);\n\n// after\nvar envVar = new EnvironmentVariable(entry.Key, entry.Value ?? string.Empty);","handlingStrategy":"validation","validationCode":"if (value is null)\n    value = string.Empty; // or throw, or skip\nvar envVar = new EnvironmentVariable(key, value);","typeGuard":"static bool IsValidEnvVarValue(string? value) => value is not null;","tryCatchPattern":null,"preventionTips":["Decide on a null-value policy upfront: skip, coalesce to empty string, or throw.","Validate config schemas to ensure all environment variable values are present.","Use Dictionary<string, string> (non-nullable value) as the canonical source type."],"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"}