dotnet/wpf · error · PrintServerException
PrintSystemException.PrintServer.GetDefaultPrinter
Error message
PrintSystemException.PrintServer.GetDefaultPrinter
What it means
Thrown when LocalPrintServer fails to read the default printer while initializing property attributes. The Win32 GetDefaultPrinter call (via the spooler) failed, and the InternalPrintSystemException is rethrown as a PrintSystemException with the GetDefaultPrinter key.
Solutions
- Check whether a default printer exists (GetDefaultPrinter Win32 / Settings > Printers) before accessing DefaultPrintQueue.
- Start the Print Spooler service if it is stopped.
- Run the code in an interactive user session that has printer configuration, not a bare service context.
- Set a default printer programmatically or manually, or handle the null/no-default case explicitly.
Example fix
// before PrintQueue queue = new LocalPrintServer().DefaultPrintQueue; // throws when none set // after var server = new LocalPrintServer(); var queue = server.GetPrintQueues().FirstOrDefault(); if (queue != null) server.DefaultPrintQueue = queue; var target = server.DefaultPrintQueue ?? queue;
Defensive patterns
Strategy: fallback
Validate before calling
static bool HasDefaultPrinter()
{
var ps = new LocalPrintServer();
return ps.GetPrintQueues().Any();
} Type guard
static bool TryGetDefaultQueue(LocalPrintServer server, out PrintQueue? queue)
{
queue = server.GetPrintQueues().FirstOrDefault();
return queue != null;
} Try / catch
PrintQueue? target;
try { target = server.DefaultPrintQueue; }
catch (PrintSystemException)
{
target = server.GetPrintQueues().FirstOrDefault(); // fall back to first available
} Prevention
- Always provide a fallback when no default printer is configured
- Detect headless/service sessions and skip print features
- Prompt users to set a default printer on first run
When it happens
Trigger: Accessing LocalPrintServer.DefaultPrintQueue (or refresh of the DefaultPrintQueue attribute) on a machine where no default printer is set, or where GetDefaultPrinter fails due to spooler issues or permissions.
Common situations: Fresh Windows installs / server cores with no printers configured; service accounts and IIS app pools with no user printer profile; Spooler service stopped; RDS sessions without printer redirection.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- PrintSystemException.PrintServer.Generic
- PrintSystemException.PrintServer.Refresh
- PrintSystemException.PrintServer.SetDefaultPrinter
- PrintSystemException.PrintSystemJobInfo.Create
- PrintSystemException.PrintSystemJobInfo.Generic
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f89755303c5ed183.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/LocalPrintServer.cpp:940
else
{
//
// This means that this is not a Connection.
// Could be something else other than a local
// printer, but we don't care at this stage
//
targetPrintServer = this;
}
attributeValue->Value = gcnew PrintQueue(targetPrintServer,
defaultPrinterName);
}
attributeValue->IsInternallyInitialized = false;
}
catch (InternalPrintSystemException^ internalException)
{
throw CreatePrintServerException(internalException->HResult, "PrintSystemException.PrintServer.GetDefaultPrinter");
}
}
}
}
/*++
Routine Name:
GetUnInitializedData
Routine Description:
Initialize an array of properties with data from the Spooler service.
Arguments:
properties - array of string representing the properties to be initializedView on GitHub (pinned to 81131a70a4)