{"record":{"id":"411264f79413b163","repo":"dotnet/wpf","slug":"sr-reachserialization-nofixedpagewriter-xpsompackagingpolicy","errorCode":null,"errorMessage":"SR.ReachSerialization_NoFixedPageWriter","messagePattern":"SR\\.ReachSerialization_NoFixedPageWriter","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs","lineNumber":482,"sourceCode":"                        IXpsOMFontResourceCollection fontCollection = _xpsPartResources.GetFontResources();\n                        fontCollection.Append(fontResource);\n\n                        XpsResourceStream fontResourceStream = new XpsResourceStream(fontStreamWrapper, uri);\n                        resourceStreamCacheItem.XpsResourceStream = fontResourceStream;\n\n                        _fontsCache[resourceId] = resourceStreamCacheItem;\n\n                        resourceStream = fontResourceStream;\n                    }\n                    catch (COMException)\n                    {\n                        Invalidate();\n                        throw new PrintingCanceledException();\n                    }\n                }\n                else\n                {\n                    throw new XpsSerializationException(SR.ReachSerialization_NoFixedPageWriter);\n                }\n            }\n            else\n            {\n                resourceStream = resourceStreamCacheItem.XpsResourceStream;\n                resourceStreamCacheItem.IncRef();\n            }\n\n            return resourceStream;\n        }\n\n        /// <summary>\n        /// This is never called during printing, but we must implement it from\n        /// abstract class BasePackagingPolicy\n        /// </summary>\n        public\n        override\n        void","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMPackagingPolicy.cs#L464-L500","documentation":"AcquireResourceStreamForXpsFont requires an open fixed-page writer to attach the new font part to. If the font is not cached and _currentFixedPageXmlWriter is null (no page is open), XpsSerializationException(SR.ReachSerialization_NoFixedPageWriter) is thrown because a font part cannot be created without page context.","triggerScenarios":"Requesting a font resource stream (new resourceId not in _fontsCache) before AcquireXmlWriterForFixedPage or after ReleaseXmlWriterForFixedPage; acquiring fonts outside page scope.","commonSituations":"Custom serialization acquiring font streams in the wrong phase; continuing to fetch fonts after a page was released; reusing the policy after invalidation reset the page writer.","solutions":["Only call AcquireResourceStreamForXpsFont while a FixedPage is open (between AcquireXmlWriterForFixedPage and ReleaseXmlWriterForFixedPage).","Acquire the page writer first in your serialization order.","If the policy was invalidated by a cancel, start a new print job rather than reusing it."],"exampleFix":"// before\nvar s = policy.AcquireResourceStreamForXpsFont(id); // throws: no page open\n// after\npolicy.AcquireXmlWriterForFixedPage();\nvar s = policy.AcquireResourceStreamForXpsFont(id);\n... write font ...\npolicy.ReleaseResourceStreamForXpsFont(id);\npolicy.ReleaseXmlWriterForFixedPage();","handlingStrategy":"validation","validationCode":"if (!pageOpen) throw new InvalidOperationException(\"AcquireXmlWriterForFixedPage must be called before AcquireResourceStreamForXpsFont\");","typeGuard":"static bool CanAcquireFont(bool pageOpen) => pageOpen;","tryCatchPattern":"try { var s = policy.AcquireResourceStreamForXpsFont(id); }\ncatch (XpsSerializationException ex) { log(\"Font stream requested with no open FixedPage\", ex); }","preventionTips":["Acquire fonts strictly inside the page scope","Verify lifecycle order before resource acquisition","Reuse the same resourceId to hit the font cache","Do not use a policy after cancellation"],"tags":["wpf","xps","fonts","lifecycle"],"backgroundTag":"invalid-state-transition","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"}