{"record":{"id":"efb4d36c6a708a42","repo":"unoplatform/uno","slug":"value-must-either-be-null-or-of-type-bool-got-va","errorCode":null,"errorMessage":"Value must either be null or of type bool. Got {value} ({value.GetType().FullName})","messagePattern":"Value must either be null or of type bool\\. Got (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/CommandBar/CommandBar_Native_With_AppBarButton_Binding.xaml.cs","lineNumber":51,"sourceCode":"\t\t}\n\t}\n\n\tpublic class FromNullableBoolToCustomValueConverter : IValueConverter\n\t{\n\t\tpublic object NullOrFalseValue { get; set; }\n\n\t\tpublic object TrueValue { get; set; }\n\n\t\tpublic object Convert(object value, Type targetType, object parameter, string language)\n\t\t{\n\t\t\tif (parameter != null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentException($\"This converter does not use any parameters. You should remove \\\"{parameter}\\\" passed as parameter.\");\n\t\t\t}\n\n\t\t\tif (value != null && !(value is bool))\n\t\t\t{\n\t\t\t\tthrow new ArgumentException($\"Value must either be null or of type bool. Got {value} ({value.GetType().FullName})\");\n\t\t\t}\n\n\t\t\tif (value == null || !System.Convert.ToBoolean(value, CultureInfo.InvariantCulture))\n\t\t\t{\n\t\t\t\treturn NullOrFalseValue;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\treturn TrueValue;\n\t\t\t}\n\t\t}\n\n\t\tpublic object ConvertBack(object value, Type targetType, object parameter, string language)\n\t\t{\n\t\t\tif (parameter != null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentException($\"This converter does not use any parameters. You should remove \\\"{parameter}\\\" passed as parameter.\");\n\t\t\t}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/CommandBar/CommandBar_Native_With_AppBarButton_Binding.xaml.cs#L33-L69","documentation":"Thrown by the same converter when value is non-null but not a bool. The converter only accepts null or bool; any other runtime type (int, string, Visibility, etc.) is rejected to surface binding-mismatch bugs loudly.","triggerScenarios":"The bound source property is an int, enum, string, Visibility, or nullable-int rather than bool or bool?; the binding then hands a non-bool, non-null value to Convert.","commonSituations":"Binding to the wrong property (e.g. an enum or count instead of a boolean flag); a value converter chain feeding an incompatible type; source changed type during refactor without updating bindings.","solutions":["Bind to a bool or bool? source property.","If the source is genuinely non-bool, add an intermediate converter that maps it to bool first, or use a converter that accepts the actual type.","Inspect value.GetType().FullName in the error message to identify the unexpected type and fix the binding path or source."],"exampleFix":"// before - bound to an int property Count\n{Binding Count, Converter={StaticResource FromNullableBoolToCustomValue}}\n<!-- after - bind to a bool property, or wrap -->\n{Binding HasItems, Converter={StaticResource FromNullableBoolToCustomValue}}","handlingStrategy":"type-guard","validationCode":"if (value is not null and not bool) throw new ArgumentException(\"expected bool?\");","typeGuard":"static bool IsNullableBool(object value) => value is null or bool;","tryCatchPattern":null,"preventionTips":["Bind only bool / bool? sources to nullable-bool converters.","When chaining converters, ensure the upstream emits bool.","Inspect value.GetType().FullName in the message to identify the wrong type."],"tags":["xaml","binding","converter","type-mismatch","samples"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}