{"record":{"id":"1529885f414cdc1c","repo":"dotnet/maui","slug":"throw-new-notsupportedexception-152988","errorCode":null,"errorMessage":"throw new NotSupportedException();","messagePattern":"throw new NotSupportedException\\(\\);","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/FlowDirectionConverter.cs","lineNumber":37,"sourceCode":"\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":19,"sourceCodeEnd":41,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/FlowDirectionConverter.cs#L19-L41","documentation":"FlowDirectionConverter.ConvertTo throws a bare NotSupportedException (no message) when the value is not a FlowDirection. ConvertTo only serializes a FlowDirection back to its string form; any other type is unsupported, and the messageless exception complicates debugging.","triggerScenarios":"Calling ConvertTo with a non-FlowDirection value (an int, a string, a different enum) when serializing or round-tripping.","commonSituations":"Property-grid or XAML serializer round-trip where the property value's runtime type does not match the converter's target enum.","solutions":["Type-check before calling ConvertTo: `if (value is FlowDirection fd) ...`.","Use a more permissive converter or handle the non-FlowDirection case explicitly.","Avoid invoking the converter for values whose type you cannot guarantee."],"exampleFix":"// before\nvar s = new FlowDirectionConverter().ConvertTo(3, typeof(string));\n\n// after\nif (value is FlowDirection fd)\n    return fd.ToString();\nthrow new NotSupportedException($\"Expected FlowDirection, got {value?.GetType()}.\");","handlingStrategy":"type-guard","validationCode":"if (value is not FlowDirection) throw new NotSupportedException();","typeGuard":"static bool IsFlowDirection(object v) => v is FlowDirection;","tryCatchPattern":"try { return converter.ConvertTo(value, typeof(string)); } catch (NotSupportedException) { return value?.ToString(); }","preventionTips":["Verify the runtime type matches FlowDirection before ConvertTo.","Avoid round-tripping values of unknown enum type through this converter."],"tags":["maui","typeconverter","flowdirection","diagnostics"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}