BornToBeRoot/NETworkManager · error · ArgumentOutOfRangeException
Specified argument was out of the range of valid values…
Error message
Specified argument was out of the range of valid values. (Parameter 'fileType')
What it means
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.
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.
Example fix
// before var vm = new ExportViewModel(delete, cancel, showTypes, false, (ExportFileType)mode, path); // after var fileType = Enum.IsDefined(typeof(ExportFileType), mode) ? (ExportFileType)mode : ExportFileType.Csv; var vm = new ExportViewModel(delete, cancel, showTypes, false, fileType, path);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!Enum.IsDefined(typeof(ExportFileType), fileType))
fileType = ExportFileType.Csv; Type guard
static bool IsSupportedExportType(ExportFileType t) =>
t is ExportFileType.Csv or ExportFileType.Xml or ExportFileType.Json or ExportFileType.Txt; Try / catch
try
{
var vm = new ExportViewModel(delete, cancel, showTypes, exportSelected, fileType, path);
}
catch (ArgumentOutOfRangeException)
{
var vm = new ExportViewModel(delete, cancel, showTypes, exportSelected, ExportFileType.Csv, path);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Embedded resource…
- Embedded resource…
- Wrong time unit.
- Process could not be started!
- Process could not be started!
AI-assisted analysis of BornToBeRoot/NETworkManager@2780d65469 (2026-09-12).
Data as JSON: /api/errors/43217de5c7dbdb2b.
Report an issue: GitHub.
Appendix: source
Thrown at Source/NETworkManager/ViewModels/ExportViewModel.cs:68
{
FilePath = filePath;
switch (fileType)
{
case ExportFileType.Csv:
UseCsv = true;
break;
case ExportFileType.Xml:
UseXml = true;
break;
case ExportFileType.Json:
UseJson = true;
break;
case ExportFileType.Txt:
UseTxt = true;
break;
default:
throw new ArgumentOutOfRangeException(nameof(fileType), fileType, null);
}
}
/// <summary>
/// Gets the command to export data.
/// </summary>
public ICommand ExportCommand { get; }
/// <summary>
/// Gets the command to cancel the operation.
/// </summary>
public ICommand CancelCommand { get; }
/// <summary>
/// Gets or sets a value indicating whether to export all data.
/// </summary>
public bool ExportAll
{View on GitHub (pinned to 2780d65469)