{"record":{"id":"ad7f13256ddacabd","repo":"Humanizr/Humanizer","slug":"specified-argument-was-out-of-the-range-of-valid-v-ad7f13","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'casing')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'casing'\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/CasingExtensions.cs","lineNumber":36,"sourceCode":"    /// - <see cref=\"LetterCasing.Sentence\"/>: First character uppercased, remainder unchanged (e.g., \"Some string\")\n    /// </returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Thrown when an invalid <see cref=\"LetterCasing\"/> value is provided.</exception>\n    /// <example>\n    /// <code>\n    /// \"some string\".ApplyCase(LetterCasing.Title) => \"Some String\"\n    /// \"SOME STRING\".ApplyCase(LetterCasing.LowerCase) => \"some string\"\n    /// \"some string\".ApplyCase(LetterCasing.AllCaps) => \"SOME STRING\"\n    /// \"some string\".ApplyCase(LetterCasing.Sentence) => \"Some string\"\n    /// </code>\n    /// </example>\n    public static string ApplyCase(this string input, LetterCasing casing) =>\n        casing switch\n        {\n            LetterCasing.Title => input.Transform(To.TitleCase),\n            LetterCasing.LowerCase => input.Transform(To.LowerCase),\n            LetterCasing.AllCaps => input.Transform(To.UpperCase),\n            LetterCasing.Sentence => input.Transform(To.SentenceCase),\n            _ => throw new ArgumentOutOfRangeException(nameof(casing))\n        };\n}","sourceCodeStart":18,"sourceCodeEnd":38,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/CasingExtensions.cs#L18-L38","documentation":"Thrown by ApplyCase when the LetterCasing argument is not one of the four defined values (Title, AllCaps, LowerCase, Sentence). The method uses a switch expression whose default arm throws ArgumentOutOfRangeException, so any value produced by an invalid cast or an uninitialized enum field trips it. The exception identifies the offending parameter by name ('casing').","triggerScenarios":"Calling input.ApplyCase((LetterCasing)999), input.ApplyCase(default(LetterCasing)) is valid (Title=0) so that does NOT throw, but casting an arbitrary int outside [0..3] does. Indirectly hit when Humanize<T>(input, casing) receives an invalid LetterCasing, since that overload forwards to ApplyCase after its own Enum.IsDefined check.","commonSituations":"Deserializing a LetterCasing value from JSON/config where the numeric backing value is out of range; passing an enum parsed from unvalidated user input; storing LetterCasing in a database column as an int and later casting without validation; threading a 'style' int from another enum into ApplyCase.","solutions":["Validate with Enum.IsDefined(casing) before calling ApplyCase and fall back to a sensible default (e.g. LetterCasing.Title).","Constrain input at the boundary: parse strings with Enum.TryParse<LetterCasing> and reject unknown values rather than casting raw ints.","If the invalid value originates upstream, fix the source (serializer config, database value, or enum definition) so only defined members reach ApplyCase."],"exampleFix":"// before\nvar result = myString.ApplyCase((LetterCasing)userChoice);\n\n// after\nif (!Enum.IsDefined(typeof(LetterCasing), userChoice))\n    throw new ArgumentOutOfRangeException(nameof(userChoice));\nvar result = myString.ApplyCase((LetterCasing)userChoice);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(LetterCasing), casing))\n    throw new ArgumentOutOfRangeException(nameof(casing));\nvar result = input.ApplyCase(casing);","typeGuard":"static bool IsValidLetterCasing(LetterCasing casing) => Enum.IsDefined(typeof(LetterCasing), casing);","tryCatchPattern":"try { result = input.ApplyCase(casing); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"casing\")\n{ /* log and fall back to a defined casing */ result = input.ApplyCase(LetterCasing.Title); }","preventionTips":["Never cast arbitrary ints to LetterCasing without Enum.IsDefined.","Parse user-supplied casing with Enum.TryParse<LetterCasing> and reject unknown values.","Treat LetterCasing as a closed set at all system boundaries (config, JSON, DB)."],"tags":["argument-validation","enum","casing","argument-out-of-range"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}