HandyOrg/HandyControl · error · ArgumentException

UnexpectedParameterType

Error message

UnexpectedParameterType

What it means

Type guard in ColLayoutConverter.ConvertTo: throws ArgumentException("UnexpectedParameterType") when the value to convert is not a ColLayout instance. The converter only serializes ColLayout objects, so any other runtime type reaching ConvertTo triggers this sentinel error.

Solutions

  1. Only call ConvertTo with a ColLayout value
  2. Pattern-match with 'value is ColLayout' and handle the negative case gracefully (return base conversion) instead of throwing
  3. Validate the source type at the binding/designer call site
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/Shared/HandyControl_Shared/Tools/Converter/ColLayoutConverter.cs:55 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at src/Shared/HandyControl_Shared/Tools/Converter/ColLayoutConverter.cs:55

    {
        if (source == null) throw GetConvertFromException(null);

        return source switch
        {
            string s => FromString(s, cultureInfo),
            double d => new ColLayout((int) d),
            _ => new ColLayout(Convert.ToInt32(source, cultureInfo))
        };
    }

    [SecurityCritical]
    public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType)
    {
        if (value == null) throw new ArgumentNullException(nameof(value));

        if (destinationType == null) throw new ArgumentNullException(nameof(destinationType));

        if (!(value is ColLayout th)) throw new ArgumentException("UnexpectedParameterType");

        if (destinationType == typeof(string)) return ToString(th, cultureInfo);
        if (destinationType == typeof(InstanceDescriptor))
        {
            var ci = typeof(ColLayout).GetConstructor(new[] { typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int) });
            return new InstanceDescriptor(ci, new object[] { th.Xs, th.Sm, th.Md, th.Lg, th.Xl, th.Xxl });
        }

        throw new ArgumentException("CannotConvertType");
    }

    private static string ToString(ColLayout th, CultureInfo cultureInfo)
    {
        var listSeparator = TokenizerHelper.GetNumericListSeparator(cultureInfo);

        // Initial capacity [128] is an estimate based on a sum of:
        // 72 = 6x double (twelve digits is generous for the range of values likely)
        //  4 = 4x separator characters

View on GitHub (pinned to 2c0875ebd6)