{"record":{"id":"09e3130f779bc588","repo":"dotnet/BenchmarkDotNet","slug":"value-cannot-be-null-parameter-values","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'values')","messagePattern":"Value cannot be null\\. \\(Parameter 'values'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/BenchmarkDotNet/Jobs/Argument.cs","lineNumber":126,"sourceCode":"    /// An MSBuild property argument (<c>/p:name=value</c>).\n    /// It escapes MSBuild special characters in the value (for example, semicolons) so that\n    /// list-like values can be passed without manual encoding.\n    /// </summary>\n    [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":108,"sourceCodeEnd":143,"githubUrl":"https://github.com/dotnet/BenchmarkDotNet/blob/b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3/src/BenchmarkDotNet/Jobs/Argument.cs#L108-L143","documentation":"CreateArgumentTextRepresentation throws ArgumentNullException(nameof(values)) when the values array is null. Because values is a params parameter, a null array is only produced by explicitly passing null (e.g. new MsBuildProperty(\"name\", null) where the compiler binds null to string[]); omitting values yields an empty array, not null.","triggerScenarios":"Calling new MsBuildProperty(\"name\", null) (null binds to the params array), or passing a string[] variable that is null as the values argument.","commonSituations":"Passing a single null literal expecting an empty value, forwarding a possibly-null array variable, or constructing properties in a loop over a null collection.","solutions":["Omit values entirely for an empty property: new MsBuildProperty(\"name\").","Coalesce a null array to an empty one before passing: values ?? Array.Empty<string>().","Pass a concrete value: new MsBuildProperty(\"name\", \"value\")."],"exampleFix":"// before\njob.WithArgument(new MsBuildProperty(\"MyCustomSetting\", null));\n\n// after\njob.WithArgument(new MsBuildProperty(\"MyCustomSetting\"));","handlingStrategy":"validation","validationCode":"var safeValues = values ?? Array.Empty<string>();\njob.WithArgument(new MsBuildProperty(name, safeValues));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit the values argument for an empty property instead of passing null.","Coalesce possibly-null arrays before forwarding them.","Remember params binds a single null literal to the array, not to an element."],"tags":["msbuild","validation","argument","null"],"backgroundTag":null,"analyzedSha":"b515068b61ad1c9c9aa938b8ece4af1e7d6d85a3","analyzedAt":"2026-08-13T19:12:24.196Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}