lepoco/wpfui · error · ArgumentException
{nameof(parameter)} is not type: {typeof(TEnum)}
Error message
{nameof(parameter)} is not type: {typeof(TEnum)} What it means
The second guard in EnumToBoolConverter<TEnum>.Convert: the ConverterParameter must also be the same TEnum as the generic type. It throws ArgumentException when the XAML supplies a parameter of a different type (or omits it, leaving it null). The converter needs both operands to be the same enum to perform an EqualityComparer comparison.
Source
Thrown at src/Wpf.Ui/Converters/EnumToBoolConverter.cs:22
// All Rights Reserved.
using System.Windows.Data;
namespace Wpf.Ui.Converters;
internal class EnumToBoolConverter<TEnum> : IValueConverter
where TEnum : Enum
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not TEnum valueEnum)
{
throw new ArgumentException($"{nameof(value)} is not type: {typeof(TEnum)}");
}
if (parameter is not TEnum parameterEnum)
{
throw new ArgumentException($"{nameof(parameter)} is not type: {typeof(TEnum)}");
}
return EqualityComparer<TEnum>.Default.Equals(valueEnum, parameterEnum);
}
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
View on GitHub (pinned to ffebacd610)
Solutions
- Supply ConverterParameter using x:Static referencing a member of the exact TEnum type.
- Ensure the same EnumToBoolConverter<TEnum> specialisation is used for both value and parameter.
- Do not pass string literals as ConverterParameter to this converter.
Example fix
<!-- before -->
<Button IsDefault="{Binding DefaultButton, Converter={StaticResource EnumToBoolConverter}, ConverterParameter=Primary}" />
<!-- after -->
<Button IsDefault="{Binding DefaultButton, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static ui:ContentDialogButton.Primary}}" /> Defensive patterns
Strategy: type-guard
Validate before calling
if (parameter is not TEnum)
{
throw new ArgumentException($"ConverterParameter must be {typeof(TEnum)}.", nameof(parameter));
} Type guard
static bool IsValidParameter(object? p) => p is TEnum;
Try / catch
try { return converter.Convert(value, targetType, parameter, culture); }
catch (ArgumentException ex) when (ex.Message.Contains("parameter") && ex.Message.Contains("is not type"))
{
_logger.LogError(ex, "EnumToBoolConverter needs an x:Static ConverterParameter");
return DependencyProperty.UnsetValue;
} Prevention
- Always pass ConverterParameter as {x:Static ns:EnumType.Member}.
- Never use string literals as the ConverterParameter for this converter.
- Use the same EnumToBoolConverter<TEnum> specialisation for value and parameter.
When it happens
Trigger: XAML supplies ConverterParameter as a string, an int, a different enum, or leaves it unset; binding uses x:Static pointing at the wrong enum type.
Common situations: Typing ConverterParameter="Primary" as a literal string instead of {x:Static ...}; copying a converter usage and forgetting to update the x:Static reference; mismatched enum types between value and parameter.
Related errors
- {nameof(value)} is not type: {typeof(TEnum)}
- ExceptionEnumToBooleanConverterParameterMustBeAnEnumName
- ExceptionEnumToBooleanConverterValueMustBeAnEnum
- Unsupported button type: {buttonType}.
- Unable to find the base directory of the application.
AI-assisted analysis of lepoco/wpfui@ffebacd610 (2026-08-13).
Data as JSON: /api/errors/4b13d4b7382029bf.
Report an issue: GitHub.