{"record":{"id":"badc2040a9678582","repo":"dotnet/maui","slug":"cannot-convert-strvalue-into-typeof-flowdirec","errorCode":null,"errorMessage":"Cannot convert \"{strValue}\" into {typeof(FlowDirection)}","messagePattern":"Cannot convert \"(.+?)\" into (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/FlowDirectionConverter.cs","lineNumber":31,"sourceCode":"\t\t\t=> destinationType == typeof(string);\n\n\t\tpublic override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)\n\t\t{\n\t\t\tvar strValue = value?.ToString();\n\n\t\t\tif (strValue != null)\n\t\t\t{\n\t\t\t\tif (Enum.TryParse(strValue, out FlowDirection direction))\n\t\t\t\t\treturn direction;\n\n\t\t\t\tif (strValue.Equals(\"ltr\", StringComparison.OrdinalIgnoreCase))\n\t\t\t\t\treturn FlowDirection.LeftToRight;\n\t\t\t\tif (strValue.Equals(\"rtl\", StringComparison.OrdinalIgnoreCase))\n\t\t\t\t\treturn FlowDirection.RightToLeft;\n\t\t\t\tif (strValue.Equals(\"inherit\", StringComparison.OrdinalIgnoreCase))\n\t\t\t\t\treturn FlowDirection.MatchParent;\n\t\t\t}\n\t\t\tthrow new InvalidOperationException($\"Cannot convert \\\"{strValue}\\\" into {typeof(FlowDirection)}\");\n\t\t}\n\n\t\tpublic override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)\n\t\t{\n\t\t\tif (value is not FlowDirection direction)\n\t\t\t\tthrow new NotSupportedException();\n\t\t\treturn direction.ToString();\n\t\t}\n\t}\n}","sourceCodeStart":13,"sourceCodeEnd":41,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/FlowDirectionConverter.cs#L13-L41","documentation":"FlowDirectionConverter.ConvertFrom throws InvalidOperationException when the string is non-null but cannot be parsed as a FlowDirection enum value nor matched case-insensitively against the aliases 'ltr', 'rtl', 'inherit'. Anything else (typos, localized strings, numeric forms) is rejected.","triggerScenarios":"Supplying a string like 'LeftToRight' (no alias match unless exact enum), 'left', 'right', 'auto', or a typo like 'ltr ' with trailing whitespace to a FlowDirection property through XAML or a converter.","commonSituations":"XAML authored with shorthand 'left'/'right', copy from CSS-direction semantics ('auto'), or trailing whitespace from data binding that bypasses enum parsing.","solutions":["Use the exact enum names (LeftToRight, RightToLeft, MatchParent) or the supported aliases 'ltr', 'rtl', 'inherit'.","Trim and validate the input string before assigning: `strValue?.Trim()`.","Provide a fallback in the binding (ConverterParameter or FallbackValue) for unknown strings."],"exampleFix":"<!-- before -->\n<Label FlowDirection=\"left\" />\n\n<!-- after -->\n<Label FlowDirection=\"LeftToRight\" />","handlingStrategy":"validation","validationCode":"var aliases = new[]{\"ltr\",\"rtl\",\"inherit\"}; var trimmed = strValue?.Trim(); if (Enum.TryParse<FlowDirection>(trimmed, out var fd) || (trimmed != null && aliases.Contains(trimmed.ToLower()))) { /* ok */ }","typeGuard":"static bool IsValidFlowDirection(string s) => Enum.TryParse<FlowDirection>(s, out _) || s?.ToLower() is \"ltr\" or \"rtl\" or \"inherit\";","tryCatchPattern":"try { return new FlowDirectionConverter().ConvertFrom(value); } catch (InvalidOperationException) { return FlowDirection.MatchParent; }","preventionTips":["Use exact enum names or the documented aliases.","Trim whitespace before assignment.","Validate user-supplied strings against the allowed set."],"tags":["maui","typeconverter","flowdirection","xaml"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}