{"record":{"id":"238095231ed0c3de","repo":"dotnet/BenchmarkDotNet","slug":"property-values-can-not-contain-null","errorCode":null,"errorMessage":"Property values can not contain null.","messagePattern":"Property values can not contain null\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Jobs/Argument.cs","lineNumber":130,"sourceCode":"    [PublicAPI]\n    public class MsBuildProperty : MsBuildArgument\n    {\n        public MsBuildProperty(string name, params string[] values)\n            : base(CreateArgumentTextRepresentation(name, values), escapeSpecialCharacters: true)\n        {\n        }\n\n        private static string CreateArgumentTextRepresentation(string name, string[] values)\n        {\n            if (string.IsNullOrWhiteSpace(name))\n                throw new ArgumentException(\"Property name must be non-empty.\", nameof(name));\n\n            if (values is null)\n                throw new ArgumentNullException(nameof(values));\n\n            for (int i = 0; i < values.Length; i++)\n                if (values[i] is null)\n                    throw new ArgumentException(\"Property values can not contain null.\", nameof(values));\n\n            string value = values.Length switch\n            {\n                0 => string.Empty,\n                1 => values[0],\n                _ => string.Join(\";\", values)\n            };\n\n            return $\"/p:{name}={value}\";\n        }\n    }\n}\n","sourceCodeStart":112,"sourceCodeEnd":143,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Jobs/Argument.cs#L112-L143","documentation":"Thrown by CreateArgumentTextRepresentation when building an MSBuild-style /p:{name}={value} argument string and one of the provided string values in the array is null. This is a defensive precondition check: the method already guards against a null array and an empty name, then iterates each element to ensure none is null before joining them with ';'. A null element would otherwise silently produce a malformed argument like /p:Prop=a;foo; where a segment is missing.","triggerScenarios":"Calling an API that internally constructs Argument text (e.g. Job/Characteristic settings that map to MSBuild properties) and passing a string[] that contains a null element. The loop `for (int i = 0; i < values.Length; i++) if (values[i] is null)` triggers the ArgumentException with paramName 'values'.","commonSituations":"Building a Job with array-valued properties (like environment variables or multi-value MSBuild properties) where one slot was never assigned, default-initialized to null, or came from a LINQ Select that returned null for a missing entry. Often seen when dynamically assembling argument lists from configuration dictionaries where some keys lack values.","solutions":["Filter out null entries before passing the array: values = values.Where(v => v != null).ToArray()","Ensure every element is assigned a non-null string when constructing the values array programmatically.","If nulls are semantically meaningful, decide on a sentinel (empty string) and coalesce: values.Select(v => v ?? string.Empty).ToArray()"],"exampleFix":"// before\nvar values = new string[] { \"a\", null, \"b\" };\nvar arg = Argument.CreateArgumentTextRepresentation(\"Prop\", values);\n\n// after\nvar values = new string[] { \"a\", null, \"b\" }\n    .Where(v => v != null)\n    .ToArray();\nvar arg = Argument.CreateArgumentTextRepresentation(\"Prop\", values);","handlingStrategy":"validation","validationCode":"string[] values = /* ... */;\nif (values != null && values.Any(v => v is null))\n    values = values.Where(v => v != null).ToArray();\n// safe to pass now","typeGuard":"static bool HasNoNulls(string[] values) => values != null && values.All(v => v is not null);","tryCatchPattern":null,"preventionTips":["Initialize string arrays with all elements assigned, never rely on default null.","Use LINQ .Where(v => v != null) as a pipeline step before passing arrays to argument builders.","Enable nullable reference types (NRT) in C# to get compile-time warnings for potential nulls."],"tags":["argument-validation","msbuild-properties","null-check"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}