dotnet/wpf · error · PtsException

SR.Format(SR.FormatRestrictionsExceeded, fserr)

Error message

SR.Format(SR.FormatRestrictionsExceeded, fserr)

What it means

Pts.Error maps error codes returned by the native PTS (Page/Tex­ture Services) layout engine to .NET exceptions. When the code is tserrSystemRestrictionsExceeded (reported via FormatRestrictionsExceeded), the native formatter exceeded its system/format restrictions — the requested layout (column count, page size, constraints, formatting complexity) is beyond what PTS accepts — and a PtsException is thrown naming the code.

Solutions

  1. Check the page/column/paragraph properties your code supplies to the flow document layout (PageSize, ColumnWidth, padding) and bring them within sane positive bounds.
  2. Verify the fserr code in the message against PTS error constants to identify which restriction (e.g. page too long vs. system restrictions) was exceeded.
  3. Reset the document viewer/page metrics to defaults to confirm the failure is caused by custom layout parameters.
  4. If it occurs with default settings, treat it as an internal layout invariant failure and gather the document structure for a WPF bug report, wrapping layout in a try/catch on PtsException.

Example fix

// before
viewer.Document.DocumentPaginator.PageSize = new Size(0, 0); // violates PTS restrictions
// after
viewer.Document.DocumentPaginator.PageSize = new Size(816, 1056); // valid page size
Defensive patterns

Strategy: try-catch

Validate before calling

bool pageSizeIsValid = paginator.PageSize.Width > 0 && paginator.PageSize.Height > 0 && !double.IsInfinity(paginator.PageSize.Width) && !double.IsInfinity(paginator.PageSize.Height);

Type guard

static bool IsValidPageSize(Size s) => !s.IsEmpty && s.Width > 0 && s.Height > 0 && double.IsFinite(s.Width) && double.IsFinite(s.Height);

Try / catch

try { viewer.UpdateLayout(); }
catch (PtsException ex) when (ex.Message.Contains("restrictions")) { ResetLayoutToDefaults(viewer); }

Prevention

When it happens

Trigger: Validating/formatting a document with a ComplexColumnProperties/flow document layout whose parameters (page width/height, column rules, para properties) violate native PTS restrictions, reached via PtsContext.Validate callbacks during page layout of a FlowDocumentPage/DocumentPage.

Common situations: Extremely large or zero/negative page dimensions, aggressive multi-column settings, or custom page views supplying out-of-range layout constraints; typically surfaces after programmatic document/page-size changes rather than normal XAML use.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Pts.cs:70

                case fserrOutOfMemory:
                    throw new OutOfMemoryException();

                case fserrCallbackException:
                    Debug.Assert(ptsContext != null, "Null argument 'ptsContext' - required for return value validation.");
                    if (ptsContext != null)
                    {
                        SecondaryException se = new SecondaryException(ptsContext.CallbackException);
                        ptsContext.CallbackException = null;
                        throw se;
                    }
                    else
                    {
                        throw new Exception(SR.Format(SR.PTSError, fserr));
                    }

                case tserrPageTooLong:
                case tserrSystemRestrictionsExceeded:
                    throw new PtsException(SR.Format(SR.FormatRestrictionsExceeded, fserr));

                default:
                    throw new PtsException(SR.Format(SR.PTSError, fserr));
            }
        }
        internal static void ValidateAndTrace(int fserr, PtsContext ptsContext)
        {
            if (fserr != fserrNone) 
            { 
                ErrorTrace(fserr, ptsContext); 
            }
        }
        private static void ErrorTrace(int fserr, PtsContext ptsContext)
        {
            switch (fserr)
            {
                case fserrOutOfMemory:
                    throw new OutOfMemoryException();

View on GitHub (pinned to 81131a70a4)