{"record":{"id":"0e58cbeadad61f86","repo":"dotnet/wpf","slug":"reachpackaging-notaprintticket","errorCode":null,"errorMessage":"ReachPackaging_NotAPrintTicket","messagePattern":"ReachPackaging_NotAPrintTicket","errorType":"exception","errorClass":"XpsPackagingException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs","lineNumber":316,"sourceCode":"            get\n            {\n                if( _printTicket == null )\n                {\n                    _printTicket = CurrentXpsManager.EnsurePrintTicket( Uri );\n                }\n                return _printTicket;\n            }\n            set\n            {\n                if(value != null)\n                {\n                    if (_isPrintTicketCommitted)\n                    {\n                        throw new XpsPackagingException(SR.ReachPackaging_PrintTicketAlreadyCommitted);\n                    }\n                    if (!value.GetType().Equals(typeof(PrintTicket)))\n                    {\n                        throw new XpsPackagingException(SR.ReachPackaging_NotAPrintTicket);\n                    }\n\n                    _printTicket = value.Clone();\n                }\n                else\n                {\n                    _printTicket = null;\n                }\n            }\n        }\n\n        /// <summary>\n        /// Gets a collection of all fixed pages that are contained within\n        /// this fixed document.\n        /// </summary>\n        /// <value>\n        /// Value is a Collection containing IXpsFixedPageReader interfaces.\n        /// </value>","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsFixedDocumentReaderWriter.cs#L298-L334","documentation":"The PrintTicket setter of XpsFixedDocumentReaderWriter throws XpsPackagingException when the assigned value is not exactly of type System.Printing.PrintTicket. The check uses value.GetType().Equals(typeof(PrintTicket)), so even PrintTicket subclasses are rejected. This ensures the stored ticket can be cloned and serialized correctly.","triggerScenarios":"Assigning an object to XpsFixedDocumentReaderWriter.PrintTicket whose runtime type is a PrintTicket subclass or an entirely different type (e.g. from a loosely-typed settings store or deserializer).","commonSituations":"Settings frameworks returning derived ticket types; reflection- or DI-based construction of tickets; code refactored to a custom PrintTicket subclass for extra state.","solutions":["Assign an instance whose runtime type is exactly System.Printing.PrintTicket.","If you have a subclass, round-trip its settings through GetXmlStream into a new base PrintTicket before assigning.","Fix the source of the object (settings store/deserializer) to return the exact PrintTicket type."],"exampleFix":"// before\nMyPrintTicket custom = LoadTicket();\nfixedDocument.PrintTicket = custom; // throws: not exactly PrintTicket\n// after\nvar ticket = new PrintTicket(custom.GetXmlStream());\nfixedDocument.PrintTicket = ticket;","handlingStrategy":"type-guard","validationCode":"if (value != null && value.GetType() != typeof(PrintTicket))\n    value = new PrintTicket(((PrintTicket)value).GetXmlStream());","typeGuard":"bool IsExactPrintTicket(object v) => v is PrintTicket && v.GetType() == typeof(PrintTicket);","tryCatchPattern":"try { fixedDocument.PrintTicket = ticket; }\ncatch (XpsPackagingException) { fixedDocument.PrintTicket = new PrintTicket(ticket.GetXmlStream()); }","preventionTips":["Avoid PrintTicket subclasses when passing tickets to XPS APIs.","Normalize any ticket to base PrintTicket at the boundary of your code.","Assert types in unit tests for settings that supply tickets."],"tags":["wpf","xps","printticket","type-mismatch"],"backgroundTag":"type-mismatch","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"}