{"record":{"id":"96549ac9814defea","repo":"dotnet/wpf","slug":"getpage","errorCode":null,"errorMessage":"getPage","messagePattern":"getPage","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/printcontext.cs","lineNumber":206,"sourceCode":"\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)\n                {\n                    throw new ArgumentNullException(\"getPage\");\n                }\n\n                this.StartDoc(jobName);\n\n                int pageNo = 0;\n\n                Visual visual = getPage(this);\n\n                while (!_cancel && (visual != null))\n                {\n                    string uri = this.StartPage(pageNo);\n\n                    this.Render(visual, uri);\n                    this.EndPage();\n\n                    pageNo++;\n\n                    visual = getPage(this);","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/printcontext.cs#L188-L224","documentation":"PrintContext.Print throws ArgumentNullException with parameter name \"getPage\" when the GetPageCallback delegate is null. Print iterates pages by invoking this callback, so without it no pages can be produced.","triggerScenarios":"Calling printContext.Print(null, jobName) — e.g. when the delegate was built conditionally and never assigned, or a method group reference resolved to null after refactoring.","commonSituations":"Custom print pipelines where the page-content provider is constructed asynchronously and not ready at Print time; refactoring that removed the page-rendering method while keeping the Print call.","solutions":["Ensure a non-null GetPageCallback (e.g. a method that returns each page's Visual) before calling Print","Validate the delegate early and report a configuration error instead of crashing at print time","Combine with XpsDocumentWriter/PrintDialog flows that guarantee a callback is supplied"],"exampleFix":"// before\ncontext.Print(null, \"Job\"); // throws\n// after\nGetPageCallback cb = (pageNumber) => RenderPage(pageNumber);\ncontext.Print(cb, \"Job\");","handlingStrategy":"validation","validationCode":"if (getPage == null)\n    throw new InvalidOperationException(\"A GetPageCallback must be supplied to print.\");","typeGuard":null,"tryCatchPattern":"try { context.Print(getPage, jobName); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"getPage\") { Log(\"Page-render callback missing\"); }","preventionTips":["Wire the page-render callback before initiating printing","Verify the delegate survives refactors by referencing the method group explicitly","Validate the whole print pipeline (queue + callback + ticket) before StartDoc"],"tags":["wpf","printing","null-argument","delegate"],"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"}