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

  1. Type-check before calling ConvertTo: `if (value is FlowDirection fd) ...`.
  2. Use a more permissive converter or handle the non-FlowDirection case explicitly.
  3. 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

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


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/1529885f414cdc1c. Report an issue: GitHub.