{"record":{"id":"67c5bf1879ee5dd5","repo":"AvaloniaUI/Avalonia","slug":"value-must-be-less-than-10","errorCode":null,"errorMessage":"Value must be less than 10.","messagePattern":"Value must be less than 10\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"warning","filePath":"samples/BindingDemo/ViewModels/ExceptionErrorViewModel.cs","lineNumber":21,"sourceCode":"\nnamespace BindingDemo.ViewModels\n{\n    public class ExceptionErrorViewModel : ViewModelBase\n    {\n        private int _lessThan10;\n\n        public int LessThan10\n        {\n            get { return _lessThan10; }\n            set\n            {\n                if (value < 10)\n                {\n                    this.RaiseAndSetIfChanged(ref _lessThan10, value);\n                }\n                else\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value), \"Value must be less than 10.\");\n                }\n            }\n        }\n    }\n}\n","sourceCodeStart":3,"sourceCodeEnd":27,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/samples/BindingDemo/ViewModels/ExceptionErrorViewModel.cs#L3-L27","documentation":"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.","triggerScenarios":"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)).","commonSituations":"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.","solutions":["Enter a value less than 10 to satisfy the validator.","If adapting the sample for real use, replace the throw with INotifyDataErrorInfo or a validation attribute for clearer UX.","Let the binding layer catch the exception and show it as a validation error rather than crashing."],"exampleFix":"// before\nif (value < 10) this.RaiseAndSetIfChanged(ref _lessThan10, value);\nelse throw new ArgumentOutOfRangeException(nameof(value), \"Value must be less than 10.\");\n\n// after (graceful validation via ReactiveUI)\nif (value >= 10) { this.ValidationObservable(...); return; }\nthis.RaiseAndSetIfChanged(ref _lessThan10, value);","handlingStrategy":"validation","validationCode":"if (value >= 10) { /* show validation error to user instead of throwing */ return; }","typeGuard":"function isLessThan10(v: number): boolean { return typeof v === 'number' && v < 10; }","tryCatchPattern":"try { viewModel.LessThan10 = value; }\ncatch (e) { if (e instanceof ArgumentOutOfRangeException) { /* bind as validation error */ } else throw e; }","preventionTips":["Treat setter exceptions as validation signals via ValidatesOnExceptions.","For production, prefer INotifyDataErrorInfo over throwing.","Clamp/validate input in the UI before assignment."],"tags":["sample","binding","validation","csharp","reactiveui","argumentoutofrange"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}