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

FromNullableBoolToVisibilityConverter.Convert throws when value is non-null and not a bool, after computing the visibility mapping. Only null or bool are accepted; any other type is a binding mismatch.

Source

Thrown at src/SamplesApp/SamplesApp.UnitTests.Shared/Controls/UITests/Views/Converters/FromNullableBoolToVisibilityConverter.cs:34

		}

		public VisibilityIfTrue VisibilityIfTrue { 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.");
			}

			bool inverse = this.VisibilityIfTrue == VisibilityIfTrue.Collapsed;

			Visibility visibilityOnTrue = (!inverse) ? Visibility.Visible : Visibility.Collapsed;
			Visibility visibilityOnFalse = (!inverse) ? Visibility.Collapsed : Visibility.Visible;

			if (value != null && !(value is bool))
			{
				throw new ArgumentException($"Value must either be null or of type bool. Got {value} ({value.GetType().FullName})");
			}

			var valueToConvert = value != null && System.Convert.ToBoolean(value, CultureInfo.InvariantCulture);

			return valueToConvert ? visibilityOnTrue : visibilityOnFalse;
		}

		public object ConvertBack(object value, Type targetType, object parameter, string language)
		{
			throw new NotSupportedException();
		}
	}

	public enum VisibilityIfTrue
	{
		Visible,
		Collapsed
	}

View on GitHub (pinned to 0418340488)

Solutions

  1. Bind to a bool / bool? source.
  2. Add an intermediate converter if the source is non-bool.
  3. Inspect value.GetType().FullName in the message.

Example fix

<!-- before -->
{Binding State, Converter={StaticResource Vis}}
<!-- after -->
{Binding IsEnabled, Converter={StaticResource Vis}}
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

When it happens

Trigger: Binding a non-bool source (int, Visibility, enum, string) to this converter.

Common situations: Wrong binding path; source type changed; chaining a converter that emits a non-bool type.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/ab8ceae4c2f5991b. Report an issue: GitHub.