{"record":{"id":"43217de5c7dbdb2b","repo":"BornToBeRoot/NETworkManager","slug":"specified-argument-was-out-of-the-range-of-valid-values","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'fileType')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'fileType'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Source/NETworkManager/ViewModels/ExportViewModel.cs","lineNumber":68,"sourceCode":"    {\n        FilePath = filePath;\n\n        switch (fileType)\n        {\n            case ExportFileType.Csv:\n                UseCsv = true;\n                break;\n            case ExportFileType.Xml:\n                UseXml = true;\n                break;\n            case ExportFileType.Json:\n                UseJson = true;\n                break;\n            case ExportFileType.Txt:\n                UseTxt = true;\n                break;\n            default:\n                throw new ArgumentOutOfRangeException(nameof(fileType), fileType, null);\n        }\n    }\n\n    /// <summary>\n    /// Gets the command to export data.\n    /// </summary>\n    public ICommand ExportCommand { get; }\n\n    /// <summary>\n    /// Gets the command to cancel the operation.\n    /// </summary>\n    public ICommand CancelCommand { get; }\n\n    /// <summary>\n    /// Gets or sets a value indicating whether to export all data.\n    /// </summary>\n    public bool ExportAll\n    {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/BornToBeRoot/NETworkManager/blob/2780d65469917a296dbc15f206107d72e2d0115c/Source/NETworkManager/ViewModels/ExportViewModel.cs#L50-L86","documentation":"The ExportViewModel constructor maps the initial ExportFileType (Csv, Xml, Json, Txt) to the corresponding Use* flag via a switch. Any ExportFileType value outside those four (or an out-of-range cast, e.g. (ExportFileType)999) hits the default case and throws ArgumentOutOfRangeException for parameter 'fileType'. This is an argument-contract guard: callers must pass one of the four supported export file types.","triggerScenarios":"Constructing ExportViewModel with a fileType argument that is not Csv/Xml/Json/Txt — typically an invalid enum cast, a new ExportFileType enum member added without updating this switch, or a caller passing an uninitialized/garbage value read from settings.","commonSituations":"New feature code adding an ExportFileType member (e.g. Markdown) and opening the export dialog before extending the switch; deserializing a persisted export-mode integer that is out of range; passing a wrong enum type that implicitly converts.","solutions":["Pass one of the supported values (ExportFileType.Csv, Xml, Json, Txt) when constructing ExportViewModel.","If a new enum member was added, extend the switch in ExportViewModel.cs:53-68 to handle it.","Clamp/validate any persisted or user-supplied value before casting it to ExportFileType and default to Csv when unknown.","Where the default case is acceptable, set a default flag instead of throwing, but keep the constructor contract documented."],"exampleFix":"// before\nvar vm = new ExportViewModel(delete, cancel, showTypes, false, (ExportFileType)mode, path);\n// after\nvar fileType = Enum.IsDefined(typeof(ExportFileType), mode) ? (ExportFileType)mode : ExportFileType.Csv;\nvar vm = new ExportViewModel(delete, cancel, showTypes, false, fileType, path);","handlingStrategy":"type-guard","validationCode":"if (!Enum.IsDefined(typeof(ExportFileType), fileType))\n    fileType = ExportFileType.Csv;","typeGuard":"static bool IsSupportedExportType(ExportFileType t) =>\n    t is ExportFileType.Csv or ExportFileType.Xml or ExportFileType.Json or ExportFileType.Txt;","tryCatchPattern":"try\n{\n    var vm = new ExportViewModel(delete, cancel, showTypes, exportSelected, fileType, path);\n}\ncatch (ArgumentOutOfRangeException)\n{\n    var vm = new ExportViewModel(delete, cancel, showTypes, exportSelected, ExportFileType.Csv, path);\n}","preventionTips":["Only pass enum values produced by Enum.IsDefined-checked sources (UI selection, not raw ints).","When adding ExportFileType members, search for all switch statements over the enum and update them.","Persist export mode as the enum name, not a numeric value, so old settings survive reordering.","Default unknown persisted values to Csv at load time instead of passing them into the ViewModel."],"tags":["csharp","enum","argument-validation","wpf"],"backgroundTag":"argument-out-of-range","analyzedSha":"2780d65469917a296dbc15f206107d72e2d0115c","analyzedAt":"2026-09-12T17:00:17.986Z","contentChangedAt":"2026-09-12T17:00:17.986Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}