{"record":{"id":"35819b2b7c90e185","repo":"LykosAI/StabilityMatrix","slug":"specified-argument-was-out-of-range-of-valid-values-35819b","errorCode":null,"errorMessage":"Specified argument was out of range of valid values.","messagePattern":"Specified argument was out of range of valid values\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Converters/NumberFormatModeSampleConverter.cs","lineNumber":27,"sourceCode":"/// Converts a <see cref=\"NumberFormatMode\"/> to a sample number string\n/// </summary>\npublic class NumberFormatModeSampleConverter : IValueConverter\n{\n    /// <inheritdoc />\n    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)\n    {\n        if (value is not NumberFormatMode mode)\n            return null;\n\n        const double sample = 12345.67;\n\n        // Format the sample number based on the number format mode\n        return mode switch\n        {\n            NumberFormatMode.Default => sample.ToString(\"N2\", culture),\n            NumberFormatMode.CurrentCulture => sample.ToString(\"N2\", culture),\n            NumberFormatMode.InvariantCulture => sample.ToString(\"N2\", CultureInfo.InvariantCulture),\n            _ => throw new ArgumentOutOfRangeException()\n        };\n    }\n\n    /// <inheritdoc />\n    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)\n    {\n        throw new NotSupportedException();\n    }\n}\n","sourceCodeStart":9,"sourceCodeEnd":37,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Converters/NumberFormatModeSampleConverter.cs#L9-L37","documentation":"NumberFormatModeSampleConverter.Convert formats a sample number according to a NumberFormatMode enum. The switch handles Default, CurrentCulture, and InvariantCulture; any other value (uninitialized, out-of-range enum, or an enum member added later without updating this switch) falls through to the default arm and throws ArgumentOutOfRangeException with no parameter name or value.","triggerScenarios":"Calling Convert with a converter parameter (or bound enum value) that is not one of the three defined NumberFormatMode members, passing an uninitialized (0) enum value that was not mapped to a case, or adding a new NumberFormatMode member without extending the switch.","commonSituations":"Enum evolution after adding a new format mode; passing an invalid int cast to NumberFormatMode as the converter parameter; deserializing a settings value into the enum that is outside the defined range.","solutions":["Pass a valid NumberFormatMode value (Default, CurrentCulture, or InvariantCulture) as the converter parameter.","If you added a new enum member, add a corresponding case to the switch in Convert.","Validate/cast the incoming parameter with Enum.IsDefined before formatting."],"exampleFix":"// before\n_ => throw new ArgumentOutOfRangeException()\n\n// after\nvar mode = Enum.IsDefined(typeof(NumberFormatMode), rawMode)\n    ? rawMode : NumberFormatMode.Default;","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(NumberFormatMode), mode))\n    mode = NumberFormatMode.Default;","typeGuard":"static bool IsValidMode(NumberFormatMode mode) => mode is NumberFormatMode.Default or NumberFormatMode.CurrentCulture or NumberFormatMode.InvariantCulture;","tryCatchPattern":"try\n{\n    return converter.Convert(sample, typeof(string), modeParam, culture)?.ToString();\n}\ncatch (ArgumentOutOfRangeException)\n{\n    return sample.ToString(\"N2\", CultureInfo.CurrentCulture);\n}","preventionTips":["Only pass defined NumberFormatMode values as converter parameters","Update the converter switch whenever the enum gains members","Avoid casting raw ints to the enum without Enum.IsDefined"],"tags":["avalonia","converter","enum","argument-out-of-range"],"backgroundTag":"invalid-enum-value","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}