stride3d/stride · error · NotSupportedException

Requested conversion is not supported.

Error message

Requested conversion is not supported.

What it means

ColorConverter.Convert throws this NotSupportedException in DEBUG builds when it receives a value it cannot convert and which is neither null nor DependencyProperty.UnsetValue. In release builds the same condition silently returns UnsetValue instead.

Solutions

  1. Bind a value of type Color (or a type the converter supports) to the property
  2. Use Brush.Color via a path (e.g. Path="Background.(SolidColorBrush.Color)") instead of the brush itself
  3. Precede with a string-to-Color converter for hex strings
  4. Test under Debug configuration to catch the mismatch early

Example fix

// before
<Binding Path="Background" Converter="{StaticResource ColorConverter}"/>
// after
<Binding Path="Background.(SolidColorBrush.Color)" Converter="{StaticResource ColorConverter}"/>
Defensive patterns

Strategy: type-guard

Validate before calling

if (value is Color) return; // safe
if (value is SolidColorBrush brush) value = brush.Color; // normalize first

Type guard

bool IsConvertible(object v) => v is Color || v is string s && ColorConverter.ConvertFromString(s) is Color;

Try / catch

try { output = colorConverter.Convert(value, targetType, parameter, culture); }
catch (NotSupportedException) { return DependencyProperty.UnsetValue; }

Prevention

When it happens

Trigger: Binding a string, brush, or arbitrary object that is not a Color/known convertible type to a property using ColorConverter; DEBUG configuration surfacing the misuse that release swallows.

Common situations: Binding a SolidColorBrush directly instead of its Color; binding a hex string without a preceding string-to-color converter; typos in the source path returning unexpected types.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/55375221ae9fbaab. Report an issue: GitHub.

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/ColorConverter.cs:127

                        (byte)((intValue >> 16) & 255));
                }
                if (targetType.IsAssignableFrom(typeof(SolidColorBrush)))
                {
                    return new SolidColorBrush(System.Windows.Media.Color.FromArgb(
                        (byte)((intValue >> 24) & 255),
                        (byte)(intValue & 255),
                        (byte)((intValue >> 8) & 255),
                        (byte)((intValue >> 16) & 255)));
                }
                if (targetType == typeof(string))
                    return stringColor;
            }

#if DEBUG
            if (value == null || value == DependencyProperty.UnsetValue)
                return DependencyProperty.UnsetValue;

            throw new NotSupportedException("Requested conversion is not supported.");
#else
            return DependencyProperty.UnsetValue;
#endif
        }

        /// <inheritdoc/>
        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType == typeof(object))
                return value;

            return Convert(value, targetType, parameter, culture);
        }
    }
}

View on GitHub (pinned to 96fad776d2)