AvaloniaUI/Avalonia · warning · ArgumentOutOfRangeException
Give me 5 or more letter please :-)
Error message
Give me 5 or more letter please :-)
What it means
Thrown by ControlCatalog DataValidationViewModel.ExceptionInsideSetterSample setter (ArgumentOutOfRangeException) when the assigned string is null or shorter than 5 characters. Like error 13 this is deliberate sample code showing Avalonia's exception-based data validation surfaced through the binding layer.
Source
Thrown at samples/ControlCatalog/ViewModels/DataValidationViewModel.cs:37
get => _DataAnnotationsSample;
set => RaiseAndSetIfChanged(ref _DataAnnotationsSample, value);
}
public Func<object, object> Converter { get; } = new Func<object, object>(o =>
{
return $"Error: {o}";
});
private string? _ExceptionInsideSetterSample;
public string? ExceptionInsideSetterSample
{
get => _ExceptionInsideSetterSample;
set
{
if (value is null || value.Length < 5)
throw new ArgumentOutOfRangeException(nameof(value), "Give me 5 or more letter please :-)");
RaiseAndSetIfChanged(ref _ExceptionInsideSetterSample, value);
}
}
public Func<object, object> ExceptionConverter { get; } = new Func<object, object>(o =>
{
return o is Exception ex ? $"Huh, there was an Exception: {ex.Message}" : "Something went really wrong!";
});
}
View on GitHub (pinned to 11c5427268)
Solutions
- Enter a string of 5 or more characters to pass validation.
- For real apps, prefer INotifyDataErrorInfo/DataAnnotations over throwing in setters.
- Wire the binding to tolerate the exception (ValidatesOnExceptions / error template) so the UI shows the message instead of faulting.
Example fix
// before
if (value is null || value.Length < 5)
throw new ArgumentOutOfRangeException(nameof(value), "Give me 5 or more letter please :-)");
// after
if (value is null || value.Length < 5) { SetError("Min 5 characters"); return; }
RaiseAndSetIfChanged(ref _ExceptionInsideSetterSample, value); Defensive patterns
Strategy: validation
Validate before calling
if (value is null || value.Length < 5) { /* flag validation error in UI; do not throw */ return; } Type guard
static bool IsValidSample(string? v) => !string.IsNullOrEmpty(v) && v.Length >= 5;
Try / catch
try { vm.ExceptionInsideSetterSample = value; }
catch (ArgumentOutOfRangeException) { /* display as validation error via ExceptionConverter */ } Prevention
- Use INotifyDataErrorInfo/DataAnnotations in production rather than setter throws.
- Validate length in the UI before assignment.
- Bind with ValidatesOnExceptions to surface the message.
When it happens
Trigger: Assigning a string that is null or has Length < 5 to ExceptionInsideSetterSample. Bound input (e.g. a TextBox) with fewer than 5 characters triggers it so the UI displays the validation message via ExceptionConverter.
Common situations: Typing 0-4 characters (or clearing) the demo TextBox; demonstrating the 'Huh, there was an Exception' converter path; reproducing validation behavior. Intentional, not a defect.
Related errors
- Value must be less than 10.
- Transition elements have different parents.
- Controls for PageSlide must have same parent.
- Cannot determine visual parent.
- Device with the corresponding LUID not found
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/d2bc206756a80e5d.
Report an issue: GitHub.