dotnet/wpf · error · ArgumentNullException
getPage
Error message
getPage
What it means
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.
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
Example fix
// before context.Print(null, "Job"); // throws // after GetPageCallback cb = (pageNumber) => RenderPage(pageNumber); context.Print(cb, "Job");
Defensive patterns
Strategy: validation
Validate before calling
if (getPage == null)
throw new InvalidOperationException("A GetPageCallback must be supplied to print."); Try / catch
try { context.Print(getPage, jobName); }
catch (ArgumentNullException ex) when (ex.ParamName == "getPage") { Log("Page-render callback missing"); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/96549ac9814defea.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/printcontext.cs:206
// enter batching for printing
MediaContext.CurrentMediaContext.ChannelSyncMode = true;
_queue = queue;
_jobTicket = new JobTicket(queue.UserJobTicket); // Make a new copy
}
#region Print()
/// <summary>
/// Print a job
/// </summary>
public void Print(GetPageCallback getPage, string jobName)
{
try
{
if (getPage == null)
{
throw new ArgumentNullException("getPage");
}
this.StartDoc(jobName);
int pageNo = 0;
Visual visual = getPage(this);
while (!_cancel && (visual != null))
{
string uri = this.StartPage(pageNo);
this.Render(visual, uri);
this.EndPage();
pageNo++;
visual = getPage(this);View on GitHub (pinned to 81131a70a4)