{"record":{"id":"f947b934db835f10","repo":"BCUninstaller/Bulk-Crap-Uninstaller","slug":"argument-argument-has-already-been-defined","errorCode":null,"errorMessage":"Argument {argument} has already been defined","messagePattern":"Argument (.+?) has already been defined","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"source/KlocTools/IO/Arguments.cs","lineNumber":162,"sourceCode":"        /// <summary>\n        /// Adds the specified argument.\n        /// </summary>\n        /// <param name=\"argument\">The argument.</param>\n        /// <param name=\"value\">The value.</param>\n        public void Add(string argument, string value)\n        {\n            if (!_parameters.ContainsKey(argument))\n                _parameters.Add(argument, new Collection<string>());\n\n            _parameters[argument].Add(value);\n        }\n\n        public void AddSingle(string argument, string value)\n        {\n            if (!_parameters.ContainsKey(argument))\n                _parameters.Add(argument, new Collection<string>());\n            else\n                throw new ArgumentException($\"Argument {argument} has already been defined\");\n\n            _parameters[argument].Add(value);\n        }\n\n        public void Remove(string argument)\n        {\n            if (_parameters.ContainsKey(argument))\n                _parameters.Remove(argument);\n        }\n\n        /// <summary>\n        /// Determines whether the specified argument is true.\n        /// </summary>\n        /// <param name=\"argument\">The argument.</param>\n        /// <returns>\n        ///     <c>true</c> if the specified argument is true; otherwise, <c>false</c>.\n        /// </returns>\n        public bool IsTrue(string argument)","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/BCUninstaller/Bulk-Crap-Uninstaller/blob/608321de98e92297377b1eb69029af55c25504a1/source/KlocTools/IO/Arguments.cs#L144-L180","documentation":"AddSingle enforces that an argument key appears exactly once. Calling it a second time for the same key (when the key already exists in _parameters) throws ArgumentException, since a single-value argument must not be defined more than once. Contrast with Add(), which allows multiple values per key.","triggerScenarios":"Parsing CLI input where the same flag is provided twice and routed through AddSingle; a programmatic double-add of the same key.","commonSituations":"Duplicate flags in a script; two code paths adding the same argument; merged argument sources without dedup.","solutions":["Use Add() instead of AddSingle() when multiple values are acceptable.","Call Remove(argument) before AddSingle() to replace the value.","Deduplicate the input before parsing it into the Arguments object."],"exampleFix":"// before\nargs.AddSingle(\"mode\", \"a\");\nargs.AddSingle(\"mode\", \"b\"); // throws\n// after\nargs.Remove(\"mode\");\nargs.AddSingle(\"mode\", \"b\");","handlingStrategy":"validation","validationCode":"if (args.Exists(argument)) args.Remove(argument);\nargs.AddSingle(argument, value);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate input before parsing.","Prefer Add() over AddSingle() when multiple values are valid."],"tags":["cli","arguments","validation"],"backgroundTag":null,"analyzedSha":"608321de98e92297377b1eb69029af55c25504a1","analyzedAt":"2026-08-13T12:17:35.389Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}