{"record":{"id":"a8a1cd61be49c931","repo":"dotnet/wpf","slug":"sr-pathgeometry-internalreadbackerror-a8a1cd","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/PathGeometry.cs","lineNumber":460,"sourceCode":"                        byte segType = (byte)(pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegTypeMask);\n\n                        sameSegCount = 1;\n\n                        // Look for a run of same-type segments for a PolyXXXSegment.\n                        while (((segIndex + sameSegCount) < segmentCount) &&\n                            (pSegTypes[segIndex] == pSegTypes[segIndex+sameSegCount]))\n                        {\n                            sameSegCount++;\n                        }\n\n                        bool fStroked = (pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegIsAGap) == (byte)0;\n                        bool fSmooth = (pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegSmoothJoin) != (byte)0;\n\n                        if (segType == (byte)MILCoreSegFlags.SegTypeLine)\n                        {\n                            if (pointIndex+sameSegCount > pointCount)\n                            {\n                                throw new System.InvalidOperationException(SR.PathGeometry_InternalReadBackError);\n                            }\n\n                            if (sameSegCount>1)\n                            {\n                                PointCollection ptCollection = new PointCollection();\n                                for (int i=0; i<sameSegCount; i++)\n                                {\n                                    ptCollection.Add(new Point(pPoints[pointIndex+i].X, pPoints[pointIndex+i].Y));\n                                }\n                                ptCollection.Freeze();\n\n                                PolyLineSegment polySeg = new PolyLineSegment(ptCollection, fStroked, fSmooth);\n                                polySeg.Freeze();\n\n                                figure.Segments.Add(polySeg);\n                            }\n                            else\n                            {","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PathGeometry.cs#L442-L478","documentation":"Thrown in PathGeometry.AddFigureToList while reading back geometry data from the unmanaged MIL layer: a line-segment run claims more points (pointIndex + sameSegCount) than the returned point buffer holds (pointCount). This is a buffer-consistency check on data produced by the core geometry read-back, indicating the segment/point counts returned by milcore do not line up. It signals corrupted or internally inconsistent geometry data rather than bad user arguments.","triggerScenarios":"Calling PathGeometry APIs that internally call AddFigureToList (e.g. reading back path data via PathGeometry.ToString/Parse or internal flattening) when the MIL read-back reports SegTypeLine runs whose point count exceeds the total pointCount.","commonSituations":"Encountered inside WPF during serialization, hit-testing or animation of PathGeometry when the render-tier data is inconsistent; often tied to runtime/driver bugs or corrupted geometry state rather than developer error.","solutions":["Re-create the PathGeometry from trusted path data (PathGeometry.CreateFromGeometry or Geometry.Parse) instead of reusing the suspect instance","Update to a patched .NET/WPF version and current graphics drivers; search for known milcore geometry read-back fixes","Freeze the geometry before use and avoid mutating geometry that may be in use by the render thread","Catch InvalidOperationException around geometry read-back operations and fall back to a rebuilt geometry"],"exampleFix":"// before\nvar s = suspectGeometry.ToString(); // read-back may throw\n// after\nGeometry fresh = Geometry.Parse(suspectGeometry.ToString(System.Globalization.CultureInfo.InvariantCulture));\nvar s = fresh.ToString();","handlingStrategy":"try-catch","validationCode":"if (geometry == null || geometry.IsEmpty()) return Geometry.Empty;","typeGuard":null,"tryCatchPattern":"try { return pathGeometry.ToString(); }\ncatch (InvalidOperationException ex) { log(ex); return PathGeometry.CreateFromGeometry(pathGeometry).ToString(); }","preventionTips":["Rebuild geometries from path data instead of reusing instances that came from render read-backs","Freeze geometries after creation","Avoid cross-thread mutation of geometry in use by the renderer","Keep WPF runtime patched"],"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-22T01:17:13.364Z"}