dotnet/wpf · error · InvalidOperationException

SR.PathGeometry_InternalReadBackError

Error message

SR.PathGeometry_InternalReadBackError

What it means

This InvalidOperationException is thrown by PathFigure.GetFlattenedPathFigure when an internal read-back of a flattened geometry from the render tier (MIL) returns an unexpected number of figures. The code expects exactly one flattened figure; any other count means the MIL/core read-back protocol was violated, so the library raises an internal-consistency error rather than returning wrong geometry. It is not caused by invalid user input but by a failure in the internal geometry flattening pipeline.

Solutions

  1. Reproduce with a minimal PathFigure and check whether the flattening result is corrupted; simplify or rebuild the geometry (e.g. re-create the PathFigure/PathGeometry) before flattening
  2. Update .NET runtime / WPF and graphics drivers; check for known geometry-flattening bugs in your runtime version
  3. Wrap GetFlattenedPathFigure in try/catch and fall back to using the original figure or a manually flattened approximation
  4. Avoid forcing the internal read-back path; ensure geometry is frozen/read-only and built with standard segment types

Example fix

// before
var flat = pathFigure.GetFlattenedPathFigure();
// after
PathFigure flat;
try { flat = pathFigure.GetFlattenedPathFigure(); }
catch (InvalidOperationException) { flat = BuildManualPolygon(pathFigure); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (pathFigure == null || pathFigure.Segments == null || pathFigure.Segments.Count == 0) return pathFigure;

Try / catch

try { var flat = pathFigure.GetFlattenedPathFigure(); }
catch (InvalidOperationException ex) { log(ex); flat = pathFigure; }

Prevention

When it happens

Trigger: Calling PathFigure.GetFlattenedPathFigure (directly or via PathGeometry flattening, hit-testing, or WPF internals like clipping/stroke measurement) when the internal flattenedGeometry read-back returns 0 or more than 1 figures instead of exactly one.

Common situations: Hit during rendering/hit-testing of complex PathGeometry data under graphics-driver or remoting quirks; also seen when the milcore render thread returns corrupted geometry data, or with unusual segment combinations exercising the internal PathGeometry creation path.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PathFigure.cs:74

        {
            PathGeometry geometry = new PathGeometry();
            geometry.Figures.Add(this);

            PathGeometry flattenedGeometry = geometry.GetFlattenedPathGeometry(tolerance, type);

            int count = flattenedGeometry.Figures.Count;

            if (count == 0)
            {
                return new PathFigure();
            }
            else if (count == 1)
            {
                return flattenedGeometry.Figures[0];
            }
            else
            {
                throw new InvalidOperationException(SR.PathGeometry_InternalReadBackError);
            }
        }


        /// <summary>
        /// Approximate this figure with a polygonal PathFigure
        /// </summary>
        /// <returns>Returns the polygonal approximation as a PathFigure.</returns>
        public PathFigure GetFlattenedPathFigure()
        {
            return GetFlattenedPathFigure(Geometry.StandardFlatteningTolerance, ToleranceType.Absolute);
        }

        #endregion

        /// <summary>
        /// Returns true if this geometry may have curved segments
        /// </summary>

View on GitHub (pinned to 81131a70a4)