dotnet/maui · error · NotSupportedException
throw new NotSupportedException();
Error message
throw new NotSupportedException();
What it means
FlowDirectionConverter.ConvertTo throws a bare NotSupportedException (no message) when the value is not a FlowDirection. ConvertTo only serializes a FlowDirection back to its string form; any other type is unsupported, and the messageless exception complicates debugging.
Source
Thrown at src/Controls/src/Core/FlowDirectionConverter.cs:37
if (strValue != null)
{
if (Enum.TryParse(strValue, out FlowDirection direction))
return direction;
if (strValue.Equals("ltr", StringComparison.OrdinalIgnoreCase))
return FlowDirection.LeftToRight;
if (strValue.Equals("rtl", StringComparison.OrdinalIgnoreCase))
return FlowDirection.RightToLeft;
if (strValue.Equals("inherit", StringComparison.OrdinalIgnoreCase))
return FlowDirection.MatchParent;
}
throw new InvalidOperationException($"Cannot convert \"{strValue}\" into {typeof(FlowDirection)}");
}
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
{
if (value is not FlowDirection direction)
throw new NotSupportedException();
return direction.ToString();
}
}
}View on GitHub (pinned to f377ff1c5e)
Solutions
- Type-check before calling ConvertTo: `if (value is FlowDirection fd) ...`.
- Use a more permissive converter or handle the non-FlowDirection case explicitly.
- Avoid invoking the converter for values whose type you cannot guarantee.
Example fix
// before
var s = new FlowDirectionConverter().ConvertTo(3, typeof(string));
// after
if (value is FlowDirection fd)
return fd.ToString();
throw new NotSupportedException($"Expected FlowDirection, got {value?.GetType()}."); Defensive patterns
Strategy: type-guard
Validate before calling
if (value is not FlowDirection) throw new NotSupportedException();
Type guard
static bool IsFlowDirection(object v) => v is FlowDirection;
Try / catch
try { return converter.ConvertTo(value, typeof(string)); } catch (NotSupportedException) { return value?.ToString(); } Prevention
- Verify the runtime type matches FlowDirection before ConvertTo.
- Avoid round-tripping values of unknown enum type through this converter.
When it happens
Trigger: Calling ConvertTo with a non-FlowDirection value (an int, a string, a different enum) when serializing or round-tripping.
Common situations: Property-grid or XAML serializer round-trip where the property value's runtime type does not match the converter's target enum.
Related errors
- throw new NotSupportedException();
- Cannot convert "{strValue}" into {typeof(FlowDirection)}
- Cannot convert "{0}" into {1}
- No test assembly found.
- Unable to find the required services. Please add all the req
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/1529885f414cdc1c.
Report an issue: GitHub.