dotnet/maui · info · InvalidOperationException
Cannot convert {self} to {nameof(FlowDirection)}.
Error message
Cannot convert {self} to {nameof(FlowDirection)}. What it means
This throw is effectively UNREACHABLE: ToFlowDirection contains an if/else where both branches return (LeftToRight or RightToRight), so the throw statement after them can never execute under normal control flow. It exists only as defensive dead code. In practice you cannot trigger it; if you see this exception, it indicates the assembly was patched or the decompiled view differs from the running IL.
Source
Thrown at src/Controls/src/Core/EffectiveFlowDirectionExtensions.cs:49
}
else
{
return EffectiveFlowDirection.RightToLeft;
}
default:
throw new InvalidOperationException($"Cannot convert {self} to {nameof(EffectiveFlowDirection)}.");
}
}
internal static FlowDirection ToFlowDirection(this EffectiveFlowDirection self)
{
if (self.IsLeftToRight())
return FlowDirection.LeftToRight;
else
return FlowDirection.RightToLeft;
throw new InvalidOperationException($"Cannot convert {self} to {nameof(FlowDirection)}.");
}
/// <summary>Returns <see langword="true"/> if the flow direction is right-to-left. Otherwise, returns <see langword="false"/>.</summary>
/// <param name="self">The enumeration value on which this method operates.</param>
/// <returns><see langword="true"/> if the flow direction is right-to-left. Otherwise, <see langword="false"/>.</returns>
public static bool IsRightToLeft(this EffectiveFlowDirection self)
{
return (self & EffectiveFlowDirection.RightToLeft) == EffectiveFlowDirection.RightToLeft;
}
/// <summary>Returns <see langword="true"/> if the flow direction is left-to-right. Otherwise, returns <see langword="false"/>.</summary>
/// <param name="self">The enumeration value on which this method operates.</param>
/// <returns><see langword="true"/> if the flow direction is left-to-right. Otherwise, <see langword="false"/>.</returns>
public static bool IsLeftToRight(this EffectiveFlowDirection self)
{
return (self & EffectiveFlowDirection.RightToLeft) != EffectiveFlowDirection.RightToLeft;
}
View on GitHub (pinned to f377ff1c5e)
Solutions
- Treat an actual occurrence as a tooling/IL anomaly: verify the running assembly matches the source (clean rebuild, check for IL weaving/rewriting).
- If you genuinely cannot convert an EffectiveFlowDirection, normalize it with IsLeftToRight()/IsRightToLeft() checks yourself instead of relying on ToFlowDirection.
Defensive patterns
Strategy: validation
Validate before calling
// The throw is unreachable in shipped IL; defensively normalize EffectiveFlowDirection before converting.
static FlowDirection SafeToFlowDirection(EffectiveFlowDirection efd) =>
efd.IsLeftToRight() ? FlowDirection.LeftToRight : FlowDirection.RightToLeft; Type guard
static bool IsKnownEffectiveFlowDirection(EffectiveFlowDirection efd) => efd.IsLeftToRight() || efd.IsRightToLeft();
Prevention
- If you ever hit this, suspect IL rewriting/tooling — clean rebuild.
- Prefer the IsLeftToRight()/IsRightToLeft() helpers over ToFlowDirection.
- Normalize EffectiveFlowDirection values from untrusted sources.
When it happens
Trigger: Not reachable via public API in the shipped IL — the preceding if/else always returns before the throw. Would only fire if the method body were altered to make a branch non-returning.
Common situations: Essentially none in production; possibly observed in a modified/debug build or an AOT/rewriting edge case that changes control flow.
Related errors
- Cannot convert {self} to {nameof(EffectiveFlowDirection)}.
- Cannot convert "{strValue}" into {typeof(FlowDirection)}
- throw new NotSupportedException();
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/f09a2e5de3a7fea2.
Report an issue: GitHub.