HandyOrg/HandyControl · error · NotSupportedException
NotSupportedException
Error message
NotSupportedException
What it means
BooleanArr2VisibilityConverter is a one-way converter: ConvertBack is intentionally unimplemented and always throws NotSupportedException. It converts a bool[] into Visibility for display only; converting a Visibility back into a bool array has no defined mapping in this library.
Solutions
- Set the binding to Mode=OneWay when using this converter so ConvertBack is never invoked.
- Swap to a different converter if you genuinely need two-way bool[]/Visibility conversion, writing your own ConvertBack.
- Never call ConvertBack manually on this converter.
Example fix
// before
{Binding Flags, Converter={StaticResource BooleanArr2VisibilityConverter}} <!-- TwoWay on editable control -->
// after
{Binding Flags, Mode=OneWay, Converter={StaticResource BooleanArr2VisibilityConverter}} Defensive patterns
Strategy: type-guard
Validate before calling
bool usesConverterBack = binding.Mode == BindingMode.TwoWay || binding.Mode == BindingMode.OneWayToSource;
if (usesConverterBack && converter is BooleanArr2VisibilityConverter) throw new InvalidOperationException("Use Mode=OneWay with BooleanArr2VisibilityConverter"); Type guard
static bool IsOneWay(BindingBase b) => b is Binding bd && bd.Mode == BindingMode.OneWay;
Try / catch
try { var result = converter.ConvertBack(value, targetTypes, parameter, culture); } catch (NotSupportedException) { return Array.Empty<object>(); // one-way converter: no back conversion
} Prevention
- Set Mode=OneWay on every binding that uses BooleanArr2VisibilityConverter.
- Avoid using this converter on editable controls (TextBox, CheckBox) whose defaults are TwoWay.
- Write a custom two-way converter if reverse conversion is actually required.
When it happens
Trigger: Using BooleanArr2VisibilityConverter in a TwoWay or OneWayToSource binding, or calling ConvertBack directly; a binding that pushes target (Visibility) changes back to the source.
Common situations: Forgetting to set Binding Mode=OneWay (default for most controls is TwoWay on editable controls like CheckBox/ComboBox); reusing the converter in an editable control template.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- NotSupportedException
- NotSupportedException
- NotSupportedException
- Specified type ' ' is not supported.
- Can't call EndInit without first calling BeginInit.
AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14).
Data as JSON: /api/errors/6f49f61b444a6152.
Report an issue: GitHub.
Appendix: source
Thrown at src/Shared/HandyControl_Shared/Tools/Converter/BooleanArr2VisibilityConverter.cs:36
var arr = new List<bool>();
foreach (var item in values)
{
if (item is bool boolValue)
{
arr.Add(boolValue);
}
else
{
return Visibility.Collapsed;
}
}
return arr.All(item => item) ? Visibility.Visible : Visibility.Collapsed;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
View on GitHub (pinned to 2c0875ebd6)