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
Thrown by the same converter when value is non-null but not a bool. The converter only accepts null or bool; any other runtime type (int, string, Visibility, etc.) is rejected to surface binding-mismatch bugs loudly.
Source
Thrown at src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/CommandBar/CommandBar_Native_With_AppBarButton_Binding.xaml.cs:51
}
}
public class FromNullableBoolToCustomValueConverter : 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)
{
if (parameter != null)
{
throw new ArgumentException($"This converter does not use any parameters. You should remove \"{parameter}\" passed as parameter.");
}View on GitHub (pinned to 0418340488)
Solutions
- Bind to a bool or bool? source property.
- If the source is genuinely non-bool, add an intermediate converter that maps it to bool first, or use a converter that accepts the actual type.
- Inspect value.GetType().FullName in the error message to identify the unexpected type and fix the binding path or source.
Example fix
// before - bound to an int property Count
{Binding Count, Converter={StaticResource FromNullableBoolToCustomValue}}
<!-- after - bind to a bool property, or wrap -->
{Binding HasItems, Converter={StaticResource FromNullableBoolToCustomValue}} 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 only bool / bool? sources to nullable-bool converters.
- When chaining converters, ensure the upstream emits bool.
- Inspect value.GetType().FullName in the message to identify the wrong type.
When it happens
Trigger: The bound source property is an int, enum, string, Visibility, or nullable-int rather than bool or bool?; the binding then hands a non-bool, non-null value to Convert.
Common situations: Binding to the wrong property (e.g. an enum or count instead of a boolean flag); a value converter chain feeding an incompatible type; source changed type during refactor without updating bindings.
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
- Cannot convert back if both custom values are the same
AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13).
Data as JSON: /api/errors/efb4d36c6a708a42.
Report an issue: GitHub.