dotnet/maui · error · ArgumentException
EnumPicker: EnumType property must be enumeration type
Error message
EnumPicker: EnumType property must be enumeration type
What it means
This is a second copy of the EnumPicker sample used in CollectionView gallery pages. It has identical logic: the EnumType bindable property's propertyChanged callback rejects non-enum Types with ArgumentException because the picker populates its ItemsSource via Enum.GetValues, which requires an actual enumeration.
Source
Thrown at src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ScrollModeGalleries/EnumPicker.cs:22
namespace Maui.Controls.Sample.Pages.CollectionViewGalleries.ScrollModeGalleries
{
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
- Ensure only enum types are assigned: `picker.EnumType = typeof(ScrollMode);`
- Guard before assignment: `if (candidateType.GetTypeInfo().IsEnum) picker.EnumType = candidateType;`
- If binding, constrain the source property to return only enum Types.
Example fix
// before picker.EnumType = typeof(string); // after picker.EnumType = typeof(ScrollMode);
Defensive patterns
Strategy: validation
Validate before calling
var candidateType = typeof(ScrollMode);
if (candidateType.GetTypeInfo().IsEnum)
picker.EnumType = candidateType; Type guard
static bool IsEnumType(Type? type) => type?.GetTypeInfo().IsEnum ?? false;
Prevention
- Bind EnumType only to properties that return enum Types.
- Validate IsEnum before assignment in gallery/sample code.
- Add unit tests for EnumPicker covering both enum and non-enum assignments.
When it happens
Trigger: Assigning a non-enum Type to this EnumPicker's EnumType property. Occurs when binding EnumType to a gallery option backed by a non-enum type, or programmatically setting it incorrectly.
Common situations: Sample/gallery code that binds EnumType to a loosely-typed property. Copy-paste of the EnumPicker into a new gallery without verifying the bound type is an enum. Type resolution issues from reflection or dynamic code.
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/76c4a66b0291d785.
Report an issue: GitHub.