{"record":{"id":"7d1e30f036563e2a","repo":"dotnet/wpf","slug":"sr-pathgeometry-internalreadbackerror","errorCode":null,"errorMessage":"SR.PathGeometry_InternalReadBackError","messagePattern":"SR\\.PathGeometry_InternalReadBackError","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PathFigure.cs","lineNumber":74,"sourceCode":"        {\n            PathGeometry geometry = new PathGeometry();\n            geometry.Figures.Add(this);\n\n            PathGeometry flattenedGeometry = geometry.GetFlattenedPathGeometry(tolerance, type);\n\n            int count = flattenedGeometry.Figures.Count;\n\n            if (count == 0)\n            {\n                return new PathFigure();\n            }\n            else if (count == 1)\n            {\n                return flattenedGeometry.Figures[0];\n            }\n            else\n            {\n                throw new InvalidOperationException(SR.PathGeometry_InternalReadBackError);\n            }\n        }\n\n\n        /// <summary>\n        /// Approximate this figure with a polygonal PathFigure\n        /// </summary>\n        /// <returns>Returns the polygonal approximation as a PathFigure.</returns>\n        public PathFigure GetFlattenedPathFigure()\n        {\n            return GetFlattenedPathFigure(Geometry.StandardFlatteningTolerance, ToleranceType.Absolute);\n        }\n\n        #endregion\n\n        /// <summary>\n        /// Returns true if this geometry may have curved segments\n        /// </summary>","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PathFigure.cs#L56-L92","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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","Update .NET runtime / WPF and graphics drivers; check for known geometry-flattening bugs in your runtime version","Wrap GetFlattenedPathFigure in try/catch and fall back to using the original figure or a manually flattened approximation","Avoid forcing the internal read-back path; ensure geometry is frozen/read-only and built with standard segment types"],"exampleFix":"// before\nvar flat = pathFigure.GetFlattenedPathFigure();\n// after\nPathFigure flat;\ntry { flat = pathFigure.GetFlattenedPathFigure(); }\ncatch (InvalidOperationException) { flat = BuildManualPolygon(pathFigure); }","handlingStrategy":"try-catch","validationCode":"if (pathFigure == null || pathFigure.Segments == null || pathFigure.Segments.Count == 0) return pathFigure;","typeGuard":null,"tryCatchPattern":"try { var flat = pathFigure.GetFlattenedPathFigure(); }\ncatch (InvalidOperationException ex) { log(ex); flat = pathFigure; }","preventionTips":["Freeze PathFigure/PathGeometry before flattening","Use only standard segment types (Line, Bezier, Arc)","Keep geometry construction on the UI thread and avoid mutation during render","Test flattening of complex figures with the target .NET version"],"tags":["wpf","geometry","internal-error"],"backgroundTag":"internal-invariant-violation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}