dotnet/wpf · error · ArgumentException

SR.SidewaysRTLTextIsNotSupported

Error message

SR.SidewaysRTLTextIsNotSupported

What it means

GlyphRun.Initialize rejects runs that are both sideways (isSideways == true) and right-to-left (bidiLevel odd), because sideways vertical layout of RTL text is not supported by the underlying text stack. It throws ArgumentException (no parameter name).

Solutions

  1. Pass isSideways=false for RTL (odd bidiLevel) runs
  2. Normalize the run so bidiLevel is even if sideways rendering is required
  3. Split mixed-direction text into separate runs with appropriate flags

Example fix

// before
new GlyphRun(tf, bidiLevel: 1, isSideways: true, ...);
// after
new GlyphRun(tf, bidiLevel: 1, isSideways: false, ...); // RTL cannot be sideways
Defensive patterns

Strategy: validation

Validate before calling

if (isSideways && (bidiLevel & 1) != 0)
    throw new InvalidOperationException("Sideways RTL is unsupported; set isSideways=false");

Type guard

static bool IsSupportedOrientation(bool isSideways, int bidiLevel) => !isSideways || (bidiLevel & 1) == 0;

Try / catch

try { var run = new GlyphRun(...); }
catch (ArgumentException ex) when (ex.Message.Contains("sideways") || ex.Message.Contains("Sideways")) { /* retry non-sideways */ }

Prevention

When it happens

Trigger: Calling the GlyphRun constructor, TryCreate, or EndInit with isSideways=true and bidiLevel % 2 == 1, e.g. vertical Arabic or Hebrew text requested as sideways glyphs.

Common situations: East-Asian vertical layout code paths applied to RTL scripts; copying sideways=true from a Latin vertical-text implementation into an RTL run.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/7133507c507ad5c1. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs:415

                        {
                            throw new ArgumentException(SR.Format(SR.CollectionNumberOfElementsShouldBeEqualTo, characters.Count), nameof(clusterMap));
                        }
                    }
                    else
                    {
                        if (GlyphCount != characters.Count)
                            throw new ArgumentException(SR.Format(SR.CollectionNumberOfElementsShouldBeEqualTo, GlyphCount), nameof(clusterMap));
                    }
                }

                if (caretStops != null && caretStops.Count != 0)
                {
                    if (caretStops.Count != CodepointCount + 1)
                        throw new ArgumentException(SR.Format(SR.CollectionNumberOfElementsShouldBeEqualTo, CodepointCount + 1), nameof(caretStops));
                }

                if (isSideways && (bidiLevel & 1) != 0)
                    throw new ArgumentException(SR.SidewaysRTLTextIsNotSupported);

                // NOTE:  In previous versions this function would estimate the size
                // of this glyph run's bitmaps and compare it against the theoretical
                // maximum size allowed before rendering falls back to using geometry.
                // This was done in order to produce a managed exception where we might
                // hit overflow or memory allocation issues in native code.
                // We no longer own the code the produces these bitmaps so we can't reliably
                // avoid the issue here any longer.
            }
            else
            {
                ArgumentOutOfRangeException.ThrowIfEqual(renderingEmSize, double.NaN);
                ArgumentOutOfRangeException.ThrowIfNegative(renderingEmSize);
                ArgumentNullException.ThrowIfNull(glyphTypeface);
                ArgumentNullException.ThrowIfNull(glyphIndices);

                if (glyphIndices.Count <= 0)
                    throw new ArgumentException(SR.CollectionNumberOfElementsMustBeGreaterThanZero, nameof(glyphIndices));

View on GitHub (pinned to 81131a70a4)