{"record":{"id":"2af144589db48b2b","repo":"dotnet/wpf","slug":"queue","errorCode":null,"errorMessage":"queue","messagePattern":"queue","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/printcontext.cs","lineNumber":186,"sourceCode":"            }\n        }\n    }\n\n    #region public class PrintContext\n    /// <summary>\n    /// PrintContext provides visual level printing API\n    /// </summary>\n    public class PrintContext : DispatcherObject\n    {\n        /// <summary>\n        /// Connect to a specified print queue\n        /// </summary>\n        /// <param name=\"queue\"></param>\n        public PrintContext(PrintQueue queue)\n        {\n            if( queue == null )\n            {\n               throw new ArgumentNullException(\"queue\");\n            }\n\n            // enter batching for printing\n            MediaContext.CurrentMediaContext.ChannelSyncMode = true;\n\n            _queue     = queue;\n            _jobTicket = new JobTicket(queue.UserJobTicket); // Make a new copy\n        }\n\n        #region Print()\n        /// <summary>\n        /// Print a job\n        /// </summary>\n        public void Print(GetPageCallback getPage, string jobName)\n        {\n            try\n            {\n                if (getPage == null)","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/printcontext.cs#L168-L204","documentation":"The PrintContext constructor throws ArgumentNullException with parameter name \"queue\" when a null PrintQueue is passed. A print context is meaningless without a target print queue — it is used to open the print document stream (StartDoc/EndDoc), so the queue is a mandatory dependency.","triggerScenarios":"new PrintContext(null) — typically when the PrintQueue came from a failed lookup (LocalPrintServer.GetPrintQueue returning null), an unresolved variable, or a PrintDialog whose PrintQueue was never assigned.","commonSituations":"Print-queue selection UI where no printer was chosen; print-server enumeration returning a missing queue; deserializing saved print settings referencing a removed printer.","solutions":["Validate the PrintQueue before constructing PrintContext and surface a user-facing 'select a printer' message","Resolve the queue explicitly: new PrintContext(GetValidQueue()) and fail early with a clear error if null","Handle the case where the selected printer no longer exists by re-enumerating LocalPrintServer.GetPrintQueues"],"exampleFix":"// before\nvar ctx = new PrintContext(dialog.PrintQueue); // null if user never picked a printer\n// after\nif (dialog.PrintQueue == null) { ShowSelectPrinterDialog(); return; }\nvar ctx = new PrintContext(dialog.PrintQueue);","handlingStrategy":"validation","validationCode":"if (queue == null)\n    throw new InvalidOperationException(\"A print queue must be selected before printing.\");","typeGuard":null,"tryCatchPattern":"try { var ctx = new PrintContext(queue); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"queue\") { ShowSelectPrinterDialog(); }","preventionTips":["Validate printer selection in UI before constructing PrintContext","Re-resolve the queue from LocalPrintServer if the saved printer name no longer exists","Fail early with a clear 'no printer selected' message rather than at construction"],"tags":["wpf","printing","null-argument"],"backgroundTag":"null-argument","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"}