unoplatform/uno · error · ArgumentException
Value must either be null or of type bool. Got {value} ({val
Error message
Value must either be null or of type bool. Got {value} ({value.GetType().FullName}) What it means
Same design as error 106 in the unit-test converter: Convert throws when value is non-null and not a bool. The test converter only accepts null or bool to keep bindings type-safe.
Source
Thrown at src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Converters/FromNullableBoolToDefaultValueConverter.cs:25
using Microsoft.UI.Xaml.Media;
namespace Uno.UI.Samples.Converters
{
public class FromNullableBoolToDefaultValueConverter : IValueConverter
{
public object NullOrFalseValue { get; set; }
public object TrueValue { get; set; }
public object Convert(object value, Type targetType, object parameter, string language)
{
if (parameter != null)
{
throw new ArgumentException($"This converter does not use any parameters. You should remove \"{parameter}\" passed as parameter.");
}
if (value != null && !(value is bool))
{
throw new ArgumentException($"Value must either be null or of type bool. Got {value} ({value.GetType().FullName})");
}
if (value == null || !System.Convert.ToBoolean(value, CultureInfo.InvariantCulture))
{
return NullOrFalseValue;
}
else
{
return TrueValue;
}
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotSupportedException();
}
}
}View on GitHub (pinned to 0418340488)
Solutions
- Bind to a bool or bool? source in the test.
- Insert an intermediate converter if the source is non-bool by design.
- Read value.GetType().FullName from the message to find the unexpected type.
Example fix
<!-- before -->
{Binding ItemCount, Converter={StaticResource Def}}
<!-- after -->
{Binding HasItems, Converter={StaticResource Def}} Defensive patterns
Strategy: type-guard
Validate before calling
if (value is not null and not bool) throw new ArgumentException("expected bool?"); Type guard
static bool IsNullableBool(object value) => value is null or bool;
Prevention
- Bind bool / bool? sources to nullable-bool converters in tests.
- Inspect value.GetType().FullName from the message to find the wrong type.
When it happens
Trigger: The test binds a non-bool, non-null source (int, string, Visibility) to this converter.
Common situations: Test fixture bound to the wrong property; value type changed without updating the test binding.
Related errors
- Value must either be null or of type bool. Got {value} ({val
- Value must either be null or of type bool. Got {value} ({val
- Value must either be null or of type bool. Got {value} ({val
- This converter does not use any parameters. You should remov
- This converter does not use any parameters. You should remov
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/0c966f2e6db5ee5c.
Report an issue: GitHub.