{"record":{"id":"4b13d4b7382029bf","repo":"lepoco/wpfui","slug":"nameof-parameter-is-not-type-typeof-tenum","errorCode":null,"errorMessage":"{nameof(parameter)} is not type: {typeof(TEnum)}","messagePattern":"(.+?) is not type: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Wpf.Ui/Converters/EnumToBoolConverter.cs","lineNumber":22,"sourceCode":"// All Rights Reserved.\n\nusing System.Windows.Data;\n\nnamespace Wpf.Ui.Converters;\n\ninternal class EnumToBoolConverter<TEnum> : IValueConverter\n    where TEnum : Enum\n{\n    public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)\n    {\n        if (value is not TEnum valueEnum)\n        {\n            throw new ArgumentException($\"{nameof(value)} is not type: {typeof(TEnum)}\");\n        }\n\n        if (parameter is not TEnum parameterEnum)\n        {\n            throw new ArgumentException($\"{nameof(parameter)} is not type: {typeof(TEnum)}\");\n        }\n\n        return EqualityComparer<TEnum>.Default.Equals(valueEnum, parameterEnum);\n    }\n\n    public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)\n    {\n        throw new NotImplementedException();\n    }\n}\n","sourceCodeStart":4,"sourceCodeEnd":33,"githubUrl":"https://github.com/lepoco/wpfui/blob/ffebacd61058170cf63864b7d5aa730cffff848a/src/Wpf.Ui/Converters/EnumToBoolConverter.cs#L4-L33","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"<!-- before -->\n<Button IsDefault=\"{Binding DefaultButton, Converter={StaticResource EnumToBoolConverter}, ConverterParameter=Primary}\" />\n\n<!-- after -->\n<Button IsDefault=\"{Binding DefaultButton, Converter={StaticResource EnumToBoolConverter}, ConverterParameter={x:Static ui:ContentDialogButton.Primary}}\" />","handlingStrategy":"type-guard","validationCode":"if (parameter is not TEnum)\n{\n    throw new ArgumentException($\"ConverterParameter must be {typeof(TEnum)}.\", nameof(parameter));\n}","typeGuard":"static bool IsValidParameter(object? p) => p is TEnum;","tryCatchPattern":"try { return converter.Convert(value, targetType, parameter, culture); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"parameter\") && ex.Message.Contains(\"is not type\"))\n{\n    _logger.LogError(ex, \"EnumToBoolConverter needs an x:Static ConverterParameter\");\n    return DependencyProperty.UnsetValue;\n}","preventionTips":["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."],"tags":["converter","enum","converterparameter","wpf"],"backgroundTag":null,"analyzedSha":"ffebacd61058170cf63864b7d5aa730cffff848a","analyzedAt":"2026-08-13T21:36:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}