CommunityToolkit / CommunityToolkit/Maui

[BUG] NumericValidationBehavior throws ArgumentNullException

Open
#2,984 3 comments 1 reaction 0 assignees View on GitHub
bug unverified
Dominant language
C#
Stars
2.7k
Forks
500
Avg merge
2d 14h
Merged PRs (30d)
7

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Did you read the "Reporting a bug" section on Contributing file?

- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

### Current Behavior

Assume an `Entry` with the `Flags` property set to `ValidateOnAttaching` and `Text` bound to a nullable string property.
When loading the page view, an `ArgumentNullException` is thrown.

```
System.ArgumentNullException: Value cannot be null. (Parameter 'value')
at System.ArgumentNullException.Throw(String paramName)
at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName)
at CommunityToolkit.Maui.Behaviors.NumericValidationBehavior.ValidateAsync(String value, CancellationToken token) in /_/src/CommunityToolkit.Maui/Behaviors/Validators/NumericValidationBehavior.shared.cs:line 79
at CommunityToolkit.Maui.Behaviors.ValidationBehavior`1[[System.String, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ValidateAsync(Object value, CancellationToken token) in /_/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs:line 463
at CommunityToolkit.Maui.Behaviors.ValidationBehavior.UpdateStateAsync(VisualElement view, ValidationFlags flags, Boolean isForced, Nullable`1 parentToken) in /_/src/CommunityToolkit.Maui/Behaviors/Validators/ValidationBehavior.shared.cs:line 382
```

### Expected Behavior

* No exception
* `IsValid` set to `False`

### Steps To Reproduce

1. Open the project in the linked repository
2. Run the application in the Android emulator
3. Observe the exception being thrown on the loading of MainPage

### Link to public reproduction project repository

https://github.com/Niels-R/ExceptionExample

### Environment

```markdown
- .NET MAUI CommunityToolkit: 13.0.0
- OS: macOS Tahoe 26.0.1 (25A362)
- .NET MAUI: 10.0.11
```

### Anything else?

This bug has been reported before, but without a working sample to reproduce.

https://github.com/CommunityToolkit/Maui/issues/979

Contributor guide

Open the contributing guide

Research direction

Start at src/CommunityToolkit.Maui/Behaviors/Validators/NumericValidationBehavior.shared.cs line 79 and reproduce the failure using the linked ExceptionExample project on Android. Verify that attaching NumericValidationBehavior to a nullable bound Entry no longer throws and that IsValid is set to False; review issue #979 for prior context.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.