{"record":{"id":"0f9391096284d656","repo":"dotnet/wpf","slug":"value-printcontext","errorCode":null,"errorMessage":"value","messagePattern":"value","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/printcontext.cs","lineNumber":272,"sourceCode":"            {\n                _cancel = value;\n            }\n        }\n\n        /// <summary>\n        /// JobTicket property\n        /// </summary>\n        public JobTicket JobTicket\n        {\n            get\n            {\n                return _jobTicket;\n            }\n            set\n            {\n                if( value == null )\n                {\n                    throw new ArgumentNullException(\"value\");\n                }\n                _jobTicket = value;\n            }\n        }\n\n        private bool IsPremium()\n        {\n            if (_queue.IsDualHeaded)\n            {\n                return true;\n            }\n\n            // Temp solution to allow premium printing on normal print queue\n            if ((_queue.Comment != null) && (_queue.Comment.Length >= 4))\n            {\n                return (_queue.Comment[0] == 'x') || (_queue.Comment[0] == 'e');\n            }\n","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/printcontext.cs#L254-L290","documentation":"The PrintContext.JobTicket property setter throws ArgumentNullException with parameter name \"value\" when assigning null. A PrintTicket is required once exposed; setting it to null is rejected instead of clearing the ticket.","triggerScenarios":"printContext.JobTicket = null — e.g. clearing print settings, propagating a possibly-null ticket from PrintDialog.PrintTicket, or default-initializing the property.","commonSituations":"Print dialogs whose PrintTicket was never initialized; resetting user preferences; copying settings between contexts where one has no ticket.","solutions":["Only assign a valid PrintTicket instance; if you need 'no ticket', skip the assignment entirely (use the default ticket)","Guard: if (ticket != null) context.JobTicket = ticket;","Initialize the ticket via PrintDialog.PrintTicket or queue.DefaultPrintTicket so a valid object always exists"],"exampleFix":"// before\ncontext.JobTicket = dialog.PrintTicket; // throws if null\n// after\nif (dialog.PrintTicket != null) context.JobTicket = dialog.PrintTicket;","handlingStrategy":"validation","validationCode":"if (ticket == null) return; // skip assignment when no ticket is available","typeGuard":"bool HasTicket(PrintContext ctx) => ctx?.JobTicket != null;","tryCatchPattern":"try { context.JobTicket = ticket; }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"value\") { /* fall back to queue.DefaultPrintTicket */ }","preventionTips":["Guard property assignment with a null check; the setter does not accept null","Initialize PrintTicket from PrintDialog.PrintTicket or queue.DefaultPrintTicket","When 'clearing' settings, rebuild the context instead of assigning null"],"tags":["wpf","printing","null-argument","property"],"backgroundTag":"null-argument","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"}