{"record":{"id":"5682602b76be4109","repo":"dotnet/wpf","slug":"sr-format-sr-ptserror-fserr","errorCode":null,"errorMessage":"SR.Format(SR.PTSError, fserr)","messagePattern":"SR\\.Format\\(SR\\.PTSError, fserr\\)","errorType":"exception","errorClass":"PtsException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Pts.cs","lineNumber":73,"sourceCode":"                case fserrCallbackException:\n                    Debug.Assert(ptsContext != null, \"Null argument 'ptsContext' - required for return value validation.\");\n                    if (ptsContext != null)\n                    {\n                        SecondaryException se = new SecondaryException(ptsContext.CallbackException);\n                        ptsContext.CallbackException = null;\n                        throw se;\n                    }\n                    else\n                    {\n                        throw new Exception(SR.Format(SR.PTSError, fserr));\n                    }\n\n                case tserrPageTooLong:\n                case tserrSystemRestrictionsExceeded:\n                    throw new PtsException(SR.Format(SR.FormatRestrictionsExceeded, fserr));\n\n                default:\n                    throw new PtsException(SR.Format(SR.PTSError, fserr));\n            }\n        }\n        internal static void ValidateAndTrace(int fserr, PtsContext ptsContext)\n        {\n            if (fserr != fserrNone) \n            { \n                ErrorTrace(fserr, ptsContext); \n            }\n        }\n        private static void ErrorTrace(int fserr, PtsContext ptsContext)\n        {\n            switch (fserr)\n            {\n                case fserrOutOfMemory:\n                    throw new OutOfMemoryException();\n\n                default:\n                    Debug.Assert(ptsContext != null, \"Null argument 'ptsContext' - required for return value validation.\"); ","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Pts.cs#L55-L91","documentation":"Pts.cs throws a PtsException wrapping the native Windows PTS (pager/text-services) error code returned by the unmanaged layout engine. The default case (SR.PTSError) fires when the native component returns an error code that is not one of the specifically translated codes (like tserrPageTooLong or tserrSystemRestrictionsExceeded). It indicates the flow-document layout engine hit an unexpected internal failure while validating the result of a native call.","triggerScenarios":"Calling Validate -> ValidateAndTrace -> Validate on a PtsContext whose native PTS call (page/table/track layout) returns an unmapped fserr code, e.g. a non-fserrNone result from the unmanaged milcore/pts host during FlowDocument measure or page layout.","commonSituations":"Corrupt or very large FlowDocument content causing the native paginator to fail; memory pressure in the native layout engine; unexpected content change during layout (illegal tree change) leaving PTS state inconsistent; native resource limits hit with codes not covered by dedicated messages.","solutions":["Inspect the fserr value in the PtsException message and match it against the tserr* constants in Pts.cs to identify the native failure","Check the FlowDocument for changes made to the logical tree during measure/arrange and defer them via Dispatcher to after layout","Reproduce with a smaller document and validate content (e.g. malformed Table or FixedDocument structures)","Repair or reinstall the .NET/WPF runtime if the native ptscomponents library is corrupted"],"exampleFix":"// before\nDispatcher.Invoke(() => document.Blocks.Add(newParagraph)); // during layout\n// after\nDispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => document.Blocks.Add(newParagraph)));","handlingStrategy":"try-catch","validationCode":"// PtsException is only thrown after a native call fails; pre-validate document structure instead\nif (flowDocument == null || flowDocument.Blocks == null) throw new InvalidOperationException(\"FlowDocument not initialized\");","typeGuard":null,"tryCatchPattern":"try\n{\n    /* measure/paginate FlowDocument */\n}\ncatch (PtsException ex)\n{\n    logger.LogError(ex, \"PTS native layout failed with code {Code}\", ex.HResult);\n    // abort pagination and fall back to re-layout with a fresh document copy\n}","preventionTips":["Never mutate the FlowDocument tree during measure/arrange; defer with Dispatcher","Keep documents within tested size/complexity limits and test pagination of large documents","Log fserr codes in PtsException messages to correlate with tserr* constants"],"tags":["wpf","flowdocument","native-interop","layout"],"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"}