HandyOrg/HandyControl · error · NotSupportedException

NotSupportedException

Error message

NotSupportedException

What it means

BorderCircularConverter computes a CornerRadius (min(width,height)/2) to make an element perfectly round; it is one-way and its ConvertBack always throws NotSupportedException. There is no meaningful inverse from CornerRadius back to the converter's inputs.

Solutions

  1. Set Mode=OneWay on any binding that uses BorderCircularConverter.
  2. Implement your own two-way converter if reverse conversion is required.
  3. Keep the converter only on display-only properties (CornerRadius of decorative borders).

Example fix

// before
<TextBox CornerRadius="{Binding Width, Converter={StaticResource BorderCircularConverter}}" />
// after
<TextBox CornerRadius="{Binding Width, Mode=OneWay, Converter={StaticResource BorderCircularConverter}}" />
Defensive patterns

Strategy: type-guard

Validate before calling

bool usesConverterBack = binding.Mode == BindingMode.TwoWay || binding.Mode == BindingMode.OneWayToSource;
if (usesConverterBack && converter is BorderCircularConverter) throw new InvalidOperationException("Use Mode=OneWay with BorderCircularConverter");

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
}

Prevention

When it happens

Trigger: Using BorderCircularConverter in a TwoWay/OneWayToSource binding (e.g. binding Border.CornerRadius where the property binding mode is TwoWay), or invoking ConvertBack directly.

Common situations: Two-way bindings on editable controls like TextBox where CornerRadius is styled; forgetting Mode=OneWay when adapting sample XAML.

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


AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14). Data as JSON: /api/errors/c138dd4f9421d955. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/HandyControl_Shared/Tools/Converter/BorderCircularConverter.cs:28

    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        if (values.Length != 2 || values[0] is not double width || values[1] is not double height)
        {
            return DependencyProperty.UnsetValue;
        }

        if (width < double.Epsilon || height < double.Epsilon)
        {
            return new CornerRadius();
        }

        var min = Math.Min(width, height);
        return new CornerRadius(min / 2);
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}

View on GitHub (pinned to 2c0875ebd6)