Skip to content

Conversation

@SubhikshaSf4851
Copy link
Contributor

@SubhikshaSf4851 SubhikshaSf4851 commented Nov 18, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

RootCause :

The current implementation of BindableObject.SetValueCore does not throw an exception when a value fails on validation.
Instead, it logs a warning and returns early.

Description of Change :

  • Updated the behavior in SetValueCore (in BindableObject.cs) to throw an ArgumentException when the ValidateValue callback returns false, instead of silently returning without setting the value.

Reference :

An exception will be raised if a validation callback returns false

Source : Microsoft Docs — Validation Callbacks
Xamarin : Reference

Issues Fixed

Fixes #25823

Tested the behavior in the following platforms

  • Windows
  • Android
  • iOS
  • Mac
Before Issue Fix After Issue Fix
BeforeFix25823.mov
AfterFix25823.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Nov 18, 2025
@dotnet-policy-service
Copy link
Contributor

Hey there @@SubhikshaSf4851! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Nov 18, 2025
@sheiksyedm sheiksyedm marked this pull request as ready for review November 18, 2025 13:25
Copilot AI review requested due to automatic review settings November 18, 2025 13:25
Copilot finished reviewing on behalf of sheiksyedm November 18, 2025 13:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a behavioral issue where BindableObject.SetValueCore was silently returning when a value failed validation, instead of throwing an exception as documented in Microsoft's official documentation. The fix changes the behavior to throw an ArgumentException when the ValidateValue callback returns false, aligning with the documented behavior and matching the pattern used in Xamarin.Forms.

Key Changes

  • Changed SetValueCore method to throw ArgumentException instead of returning silently when validation fails
  • Added comprehensive unit test to verify the exception throwing behavior
  • Maintained the error message format consistent with other validation failures in the codebase

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Controls/src/Core/BindableObject.cs Updated SetValueCore to throw ArgumentException when ValidateValue callback returns false, replacing the silent return with explicit exception throwing
src/Controls/tests/Core.UnitTests/BindablePropertyUnitTests.cs Added new test SetValueThrowsExceptionWhenValidationFails to verify that validation failures now throw ArgumentException with the correct message format


if (property.ValidateValue != null && !property.ValidateValue(this, value))
{
Application.Current?.FindMauiContext()?.CreateLogger<BindableObject>()?.LogWarning($"Value is an invalid value for {property.PropertyName}");
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LogWarning call is redundant when an exception is about to be thrown. When an exception is thrown, it's clear that an error occurred, and the exception message itself provides the necessary information. The logging statement should be removed to avoid redundant error output.

Consider removing the logging line:

if (property.ValidateValue != null && !property.ValidateValue(this, value))
{
	throw new ArgumentException($"Value is an invalid value for {property.PropertyName}", nameof(value));
}
Suggested change
Application.Current?.FindMauiContext()?.CreateLogger<BindableObject>()?.LogWarning($"Value is an invalid value for {property.PropertyName}");

Copilot uses AI. Check for mistakes.
{
Application.Current?.FindMauiContext()?.CreateLogger<BindableObject>()?.LogWarning($"Value is an invalid value for {property.PropertyName}");
return;
throw new ArgumentException($"Value is an invalid value for {property.PropertyName}", nameof(value));
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XML documentation for the SetValue method should be updated to include the new ArgumentException that can be thrown when validation fails. Looking at the code at line 473-479, the documentation currently only lists ArgumentNullException, but should also document that ArgumentException is thrown when the value fails validation.

The XML documentation should be updated to include:

/// <exception cref="ArgumentException">Thrown when the value is invalid according to the assigned logic in <see cref="BindableProperty.ValidateValueDelegate"/>.</exception>

This follows the pattern used in the CoerceValue method (line 803 in the full file context).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BindableProperty validation does not throw an ArgumentException, although it is documented as such

1 participant