dotnet/wpf · error · PrintServerException
PrintSystemException.PrintServer.Refresh
Error message
PrintSystemException.PrintServer.Refresh
What it means
Thrown by LocalPrintServer.Refresh when reloading server state fails. Refresh first re-reads the DefaultPrintQueue attribute via GetDataFromServer, then calls PrintServer::Refresh; a Win32 spooler failure anywhere in that sequence raises this PrintSystemException.
Solutions
- Ensure the Print Spooler service is running before refreshing.
- Verify at least one printer/default printer is configured in the session.
- Catch and inspect the inner HResult to identify the failing Win32 call.
- Re-create the LocalPrintServer instance instead of refreshing a stale one.
Example fix
// before
server.Refresh(); // may throw on headless/service sessions
// after
try { server.Refresh(); }
catch (PrintSystemException ex)
{
// spooler unavailable or no default printer; fall back to re-enumeration
server = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
} Defensive patterns
Strategy: retry
Validate before calling
using var sc = new ServiceController("Spooler");
sc.Refresh();
if (sc.Status != ServiceControllerStatus.Running) throw new InvalidOperationException("Spooler not running"); Type guard
static bool SpoolerRunning()
{
try { using var sc = new ServiceController("Spooler"); sc.Refresh();
return sc.Status == ServiceControllerStatus.Running; }
catch { return false; }
} Try / catch
for (int attempt = 0; attempt < 3; attempt++)
{
try { server.Refresh(); break; }
catch (PrintSystemException) when (attempt < 2) { Thread.Sleep(500); }
} Prevention
- Check Spooler service status before refresh
- Retry transient failures with backoff (spooler restarts)
- Re-create the LocalPrintServer instance if refresh keeps failing
When it happens
Trigger: Calling LocalPrintServer.Refresh() when the spooler is unavailable, the default printer lookup fails, or the underlying PrintServer refresh Win32 calls (OpenPrinter/GetPrinter) fail due to permissions.
Common situations: Print Spooler restarted or crashed between operations; environment with no printers (services, CI agents); driver/provider corruption causing GetPrinter failures.
Related errors
- PrintSystemException.PrintQueue.Populate
- PrintSystemException.PrintServer.Generic
- PrintSystemException.PrintServer.GetDefaultPrinter
- PrintSystemException.PrintSystemJobInfo.Create
- PrintSystemException.PrintSystemJobInfo.Generic
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/85afcedf923e804b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/LocalPrintServer.cpp:1103
void
--*/
void
LocalPrintServer::
Refresh(
void
)
{
VerifyAccess();
try
{
GetDataFromServer("DefaultPrintQueue", true);
PrintServer::Refresh();
}
catch (InternalPrintSystemException^ internalException)
{
throw CreatePrintServerException(internalException->HResult, "PrintSystemException.PrintServer.Refresh");
}
}
/*++
Routine Name:
GetAlteredPropertiesFilter
Routine Description:
Creates an array string representing of the dirty properties of a PrintServer object.
Arguments:
propertiesFilter - array of property strings
View on GitHub (pinned to 81131a70a4)