{"record":{"id":"d2bc206756a80e5d","repo":"AvaloniaUI/Avalonia","slug":"give-me-5-or-more-letter-please","errorCode":null,"errorMessage":"Give me 5 or more letter please :-)","messagePattern":"Give me 5 or more letter please :-\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"warning","filePath":"samples/ControlCatalog/ViewModels/DataValidationViewModel.cs","lineNumber":37,"sourceCode":"        get => _DataAnnotationsSample;\n        set => RaiseAndSetIfChanged(ref _DataAnnotationsSample, value);\n    }\n\n    public Func<object, object> Converter { get; } = new Func<object, object>(o =>\n    {\n        return $\"Error: {o}\";\n    });\n\n\n    private string? _ExceptionInsideSetterSample;\n\n    public string? ExceptionInsideSetterSample\n    {\n        get => _ExceptionInsideSetterSample;\n        set\n        {\n            if (value is null || value.Length < 5)\n                throw new ArgumentOutOfRangeException(nameof(value), \"Give me 5 or more letter please :-)\");\n\n            RaiseAndSetIfChanged(ref _ExceptionInsideSetterSample, value);\n        }\n    }\n\n    public Func<object, object> ExceptionConverter { get; } = new Func<object, object>(o =>\n    {\n        return o is Exception ex ? $\"Huh, there was an Exception: {ex.Message}\" : \"Something went really wrong!\";\n    });\n}\n","sourceCodeStart":19,"sourceCodeEnd":48,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/samples/ControlCatalog/ViewModels/DataValidationViewModel.cs#L19-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nif (value is null || value.Length < 5)\n    throw new ArgumentOutOfRangeException(nameof(value), \"Give me 5 or more letter please :-)\");\n\n// after\nif (value is null || value.Length < 5) { SetError(\"Min 5 characters\"); return; }\nRaiseAndSetIfChanged(ref _ExceptionInsideSetterSample, value);","handlingStrategy":"validation","validationCode":"if (value is null || value.Length < 5) { /* flag validation error in UI; do not throw */ return; }","typeGuard":"static bool IsValidSample(string? v) => !string.IsNullOrEmpty(v) && v.Length >= 5;","tryCatchPattern":"try { vm.ExceptionInsideSetterSample = value; }\ncatch (ArgumentOutOfRangeException) { /* display as validation error via ExceptionConverter */ }","preventionTips":["Use INotifyDataErrorInfo/DataAnnotations in production rather than setter throws.","Validate length in the UI before assignment.","Bind with ValidatesOnExceptions to surface the message."],"tags":["sample","binding","validation","csharp","argumentoutofrange"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}