{"record":{"id":"76ba085d087fbf57","repo":"Humanizr/Humanizer","slug":"specified-argument-was-out-of-the-range-of-valid-v-76ba08","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'source')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'source'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Humanizer/EnumHumanizeExtensions.cs","lineNumber":138,"sourceCode":"    ///     [Description(\"Currently active\")]\n    ///     Active \n    /// }\n    /// Status.Active.Humanize() => \"Currently active\"\n    /// </code>\n    /// </example>\n    public static string Humanize<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(this T input)\n        where T : struct, Enum =>\n        Humanize(input, null, EnumHumanizeSource.Default);\n\n    static string Humanize<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] T>(\n        T input,\n        LetterCasing? casing,\n        EnumHumanizeSource source)\n        where T : struct, Enum\n    {\n        if (!Enum.IsDefined(source))\n        {\n            throw new ArgumentOutOfRangeException(nameof(source));\n        }\n\n        var (zero, values) = EnumCache<T>.GetInfo(source);\n        if (EnumCache<T>.TreatAsFlags(input, source))\n        {\n            if (casing is { } flagsCasing && !Enum.IsDefined(flagsCasing))\n            {\n                throw new ArgumentOutOfRangeException(nameof(casing));\n            }\n\n            // Avoid LINQ allocations by manually iterating and building the list\n            List<string>? flagValues = null;\n            foreach (var value in values)\n            {\n                if (value.CompareTo(zero) != 0 && input.HasFlag(value))\n                {\n                    flagValues ??= new List<string>();\n                    var flag = EnumCache<T>.GetHumanized(value, source);","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/Humanizr/Humanizer/blob/ffc2b77c0f30d2fb176875841424379319d0ae9b/src/Humanizer/EnumHumanizeExtensions.cs#L120-L156","documentation":"Thrown inside the private Humanize<T> worker when the EnumHumanizeSource argument is not a defined member of the enum (Default, EnumName, DisplayName, DisplayDescription, DisplayShortName). The guard runs Enum.IsDefined(source) at the top of the method, before any caching/formatting, so an undefined source fails fast. The parameter is named 'source' in the exception.","triggerScenarios":"Calling enumValue.Humanize(LetterCasing.Title, (EnumHumanizeSource)99); passing an EnumHumanizeSource deserialized from an out-of-range integer; a default(EnumHumanizeSource) value is valid (=Default=0) and will NOT throw.","commonSituations":"Configuration files or databases storing the source as a raw int with an out-of-range value after an enum was reshaped; reflection-based callers that build the argument dynamically; interop with another enum that happens to be cast to EnumHumanizeSource.","solutions":["Validate with Enum.IsDefined(typeof(EnumHumanizeSource), source) before calling and coerce/reject invalid values.","Bind configuration via strongly-typed enum parsing (e.g. Enum.TryParse) rather than raw int casts.","If you only need default metadata precedence, omit the source argument entirely and call the simpler Humanize overloads."],"exampleFix":"// before\nvar text = status.Humanize(LetterCasing.Title, (EnumHumanizeSource)rawConfig);\n\n// after\nif (!Enum.IsDefined(typeof(EnumHumanizeSource), rawConfig))\n    rawConfig = (int)EnumHumanizeSource.Default;\nvar text = status.Humanize(LetterCasing.Title, (EnumHumanizeSource)rawConfig);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(EnumHumanizeSource), source))\n    source = EnumHumanizeSource.Default;\nvar text = input.Humanize(LetterCasing.Title, source);","typeGuard":"static bool IsValidSource(EnumHumanizeSource s) => Enum.IsDefined(typeof(EnumHumanizeSource), s);","tryCatchPattern":"try { return input.Humanize(casing, source); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"source\")\n{ return input.Humanize(casing, EnumHumanizeSource.Default); }","preventionTips":["Bind EnumHumanizeSource from config via enum parsing, not raw int casts.","Default to EnumHumanizeSource.Default when the source is uncertain.","Prefer the overloads that omit source when you only need default precedence."],"tags":["enum","argument-validation","humanize","argument-out-of-range"],"backgroundTag":null,"analyzedSha":"ffc2b77c0f30d2fb176875841424379319d0ae9b","analyzedAt":"2026-08-13T21:42:34.584Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}