unoplatform/uno · error · InvalidOperationException
Cannot convert back if both custom values are the same
Error message
Cannot convert back if both custom values are the same
What it means
Thrown by ConvertBack when TrueValue and NullOrFalseValue are equal. Reverse conversion maps the current value back to true/false by comparing against these two; if both are the same object/value, the mapping is ambiguous, so the converter refuses rather than guess.
Source
Thrown at src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/CommandBar/CommandBar_Native_With_AppBarButton_Binding.xaml.cs:73
{
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.");
}
if (object.Equals(this.TrueValue, this.NullOrFalseValue))
{
throw new InvalidOperationException("Cannot convert back if both custom values are the same");
}
return this.TrueValue != null ?
value.Equals(TrueValue) :
!value.Equals(this.NullOrFalseValue);
}
}
}
View on GitHub (pinned to 0418340488)
Solutions
- Give TrueValue and NullOrFalseValue distinct values in the converter resource definition.
- If you only need one-way conversion, switch the binding to Mode=OneWay so ConvertBack is never called.
- Add an XAML comment / constructor assertion documenting the distinct-values requirement.
Example fix
<!-- before --> <conv:FromNullableBoolToCustomValueConverter x:Key="C" TrueValue="Visible" NullOrFalseValue="Visible"/> <!-- after --> <conv:FromNullableBoolToCustomValueConverter x:Key="C" TrueValue="Visible" NullOrFalseValue="Collapsed"/>
Defensive patterns
Strategy: validation
Validate before calling
var conv = new FromNullableBoolToCustomValueConverter();
if (object.Equals(conv.TrueValue, conv.NullOrFalseValue))
throw new InvalidOperationException("Configure distinct TrueValue and NullOrFalseValue before two-way use."); Prevention
- Always assign distinct TrueValue and NullOrFalseValue in the resource.
- Avoid TwoWay mode if the two values would be equal.
- Add a constructor/runtime check that rejects equal values for two-way usage.
When it happens
Trigger: Configuring the converter resource with TrueValue and NullOrFalseValue set to the same value (e.g. both 'Visible', both same string, both null) and then triggering a TwoWay ConvertBack.
Common situations: XAML resource where both properties are left at default (null/null) or explicitly set equal; copy-paste error assigning the same element to both.
Related errors
- This converter does not use any parameters. You should remov
- Value must either be null or of type bool. Got {value} ({val
- This converter does not use any parameters. You should remov
- Value must either be null or of type bool. Got {value} ({val
- 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/1e0c14ddd46de25c.
Report an issue: GitHub.