dotnet/maui · error · ArgumentException
EnumPicker: EnumType property must be enumeration type
Error message
EnumPicker: EnumType property must be enumeration type
What it means
This sample EnumPicker (a Picker subclass) exposes an EnumType bindable property. When EnumType is set, the propertyChanged callback checks whether the assigned Type is an enum via IsEnum. If it is not (e.g., a class, struct, or interface), it throws ArgumentException because Enum.GetValues would fail or produce nonsensical results for a non-enum type.
Source
Thrown at src/Controls/samples/Controls.Sample/Controls/EnumPicker.cs:22
namespace Maui.Controls.Sample.Controls
{
class EnumPicker : Picker
{
public static readonly BindableProperty EnumTypeProperty =
BindableProperty.Create(nameof(EnumType), typeof(Type), typeof(EnumPicker),
propertyChanged: (bindable, oldValue, newValue) =>
{
EnumPicker picker = (EnumPicker)bindable;
if (oldValue != null)
{
picker.ItemsSource = null;
}
if (newValue != null)
{
if (!((Type)newValue).GetTypeInfo().IsEnum)
throw new ArgumentException("EnumPicker: EnumType property must be enumeration type");
picker.ItemsSource = Enum.GetValues((Type)newValue);
}
});
public Type EnumType
{
set => SetValue(EnumTypeProperty, value);
get => (Type)GetValue(EnumTypeProperty);
}
}
}View on GitHub (pinned to f377ff1c5e)
Solutions
- Only assign enumeration types to EnumType: `enumPicker.EnumType = typeof(MyEnum);`
- Add a runtime guard before assignment: `if (typeof(T).GetTypeInfo().IsEnum) enumPicker.EnumType = typeof(T);`
- Add a generic constraint `where T : struct, Enum` if EnumType is set from a generic method.
Example fix
// before enumPicker.EnumType = typeof(MySettingsClass); // not an enum // after enumPicker.EnumType = typeof(MySettingsEnum); // actual enum
Defensive patterns
Strategy: validation
Validate before calling
var candidateType = typeof(MyEnum);
if (candidateType.GetTypeInfo().IsEnum)
enumPicker.EnumType = candidateType;
else
throw new InvalidOperationException($"{candidateType.Name} is not an enum."); Type guard
static bool IsEnumType(Type? type) => type?.GetTypeInfo().IsEnum ?? false;
Prevention
- Only assign typeof() of actual enum types to EnumType.
- Add a generic constraint `where T : struct, Enum` when setting EnumType from generics.
- Validate the type with IsEnum before assignment in dynamic scenarios.
When it happens
Trigger: Binding or assigning EnumType to a Type that is not an enumeration — e.g., `enumPicker.EnumType = typeof(string)` or `enumPicker.EnumType = typeof(MyClass)`. Setting EnumType from a data source that resolves to a non-enum Type.
Common situations: Binding EnumType to a property whose type is not constrained at compile time. Passing typeof(T) where T is not an enum generic constraint. Mistakenly assigning the value type rather than the enum type. Dynamic type resolution from reflection producing a non-enum Type.
Related errors
- EnumPicker: EnumType property must be enumeration type
- Pin must have a Label to be added to a map
- Value is an invalid value for {property.PropertyName}
- mode is not a valid BindingMode
- RootComponent requires a value for its Selector property, bu
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/4880f3438b054c46.
Report an issue: GitHub.