AvaloniaUI/Avalonia · warning · ArgumentOutOfRangeException

Value must be less than 10.

Error message

Value must be less than 10.

What it means

Thrown by the BindingDemo ExceptionErrorViewModel.LessThan10 setter (ArgumentOutOfRangeException) when a value >= 10 is assigned. This is intentional sample code demonstrating Avalonia/ReactiveUI data-validation-via-exceptions: the setter rejects out-of-range input so the binding layer surfaces a validation error.

Source

Thrown at samples/BindingDemo/ViewModels/ExceptionErrorViewModel.cs:21

namespace BindingDemo.ViewModels
{
    public class ExceptionErrorViewModel : ViewModelBase
    {
        private int _lessThan10;

        public int LessThan10
        {
            get { return _lessThan10; }
            set
            {
                if (value < 10)
                {
                    this.RaiseAndSetIfChanged(ref _lessThan10, value);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(value), "Value must be less than 10.");
                }
            }
        }
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Enter a value less than 10 to satisfy the validator.
  2. If adapting the sample for real use, replace the throw with INotifyDataErrorInfo or a validation attribute for clearer UX.
  3. Let the binding layer catch the exception and show it as a validation error rather than crashing.

Example fix

// before
if (value < 10) this.RaiseAndSetIfChanged(ref _lessThan10, value);
else throw new ArgumentOutOfRangeException(nameof(value), "Value must be less than 10.");

// after (graceful validation via ReactiveUI)
if (value >= 10) { this.ValidationObservable(...); return; }
this.RaiseAndSetIfChanged(ref _lessThan10, value);
Defensive patterns

Strategy: validation

Validate before calling

if (value >= 10) { /* show validation error to user instead of throwing */ return; }

Type guard

function isLessThan10(v: number): boolean { return typeof v === 'number' && v < 10; }

Try / catch

try { viewModel.LessThan10 = value; }
catch (e) { if (e instanceof ArgumentOutOfRangeException) { /* bind as validation error */ } else throw e; }

Prevention

When it happens

Trigger: Assigning a value >= 10 to the LessThan10 property (e.g. from a bound TextBox/numeric input). RaiseAndSetIfChanged is only called for values < 10; everything else throws ArgumentOutOfRangeException(nameof(value)).

Common situations: Typing a number 10 or higher into the demo input; a bound control pushing a value at the boundary; reproducing the validation-error demo. This is by design, not a bug.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/67c5bf1879ee5dd5. Report an issue: GitHub.