dotnet/wpf · error · InvalidOperationException
SR.PathGeometry_InternalReadBackError
Error message
SR.PathGeometry_InternalReadBackError
What it means
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.
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
Example fix
// before var s = suspectGeometry.ToString(); // read-back may throw // after Geometry fresh = Geometry.Parse(suspectGeometry.ToString(System.Globalization.CultureInfo.InvariantCulture)); var s = fresh.ToString();
Defensive patterns
Strategy: try-catch
Validate before calling
if (geometry == null || geometry.IsEmpty()) return Geometry.Empty;
Try / catch
try { return pathGeometry.ToString(); }
catch (InvalidOperationException ex) { log(ex); return PathGeometry.CreateFromGeometry(pathGeometry).ToString(); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- SR.PathGeometry_InternalReadBackError
- SR.DefaultAttachablePropertyStoreCannotAddInstance
- SR.Format(SR.ParentlessPropertyElement, propName.ScopedName)
- SR.Format(SR.Rect_Empty, "rect")
- SR.MatrixNotInvertible
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a8a1cd61be49c931.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/PathGeometry.cs:460
byte segType = (byte)(pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegTypeMask);
sameSegCount = 1;
// Look for a run of same-type segments for a PolyXXXSegment.
while (((segIndex + sameSegCount) < segmentCount) &&
(pSegTypes[segIndex] == pSegTypes[segIndex+sameSegCount]))
{
sameSegCount++;
}
bool fStroked = (pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegIsAGap) == (byte)0;
bool fSmooth = (pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegSmoothJoin) != (byte)0;
if (segType == (byte)MILCoreSegFlags.SegTypeLine)
{
if (pointIndex+sameSegCount > pointCount)
{
throw new System.InvalidOperationException(SR.PathGeometry_InternalReadBackError);
}
if (sameSegCount>1)
{
PointCollection ptCollection = new PointCollection();
for (int i=0; i<sameSegCount; i++)
{
ptCollection.Add(new Point(pPoints[pointIndex+i].X, pPoints[pointIndex+i].Y));
}
ptCollection.Freeze();
PolyLineSegment polySeg = new PolyLineSegment(ptCollection, fStroked, fSmooth);
polySeg.Freeze();
figure.Segments.Add(polySeg);
}
else
{View on GitHub (pinned to 81131a70a4)