dotnet/wpf · error · PrintServerException

PrintSystemException.PrintServer.Refresh

Error message

PrintSystemException.PrintServer.Refresh

What it means

PrintServer.Refresh reloads server properties from the spooler. When GetDataFromServer fails for any refresh property with an InternalPrintSystemException, the HRESULT is re-thrown as PrintSystemException keyed 'PrintSystemException.PrintServer.Refresh'. It means reading current settings from the print server failed.

Solutions

  1. Verify connectivity to the print server and that its spooler service is running
  2. Check HResult for access-denied (5) vs RPC unavailable errors
  3. Re-create the PrintServer object with a valid name and retry Refresh
  4. Run under credentials with read access to the server

Example fix

// before
server.Refresh(); // throws if server unreachable
// after
try { server.Refresh(); }
catch (PrintSystemException ex)
{
    Console.WriteLine($"Refresh failed 0x{ex.HResult:X}; using cached values");
}
Defensive patterns

Strategy: try-catch

Validate before calling

try { Dns.GetHostEntry(serverHost); }
catch (SocketException) { throw new InvalidOperationException("Print server unreachable: " + serverHost); }

Type guard

static bool CanRefresh(PrintServer s) =>
    s != null && ServiceController
        .GetServices(s.Name == "" ? "." : s.Name)
        .Any(x => x.ServiceName == "Spooler" && x.Status == ServiceControllerStatus.Running);

Try / catch

try { server.Refresh(); }
catch (PrintSystemException ex)
{ Log.Warn($"Refresh failed 0x{ex.HResult:X}; using cached data"); }

Prevention

When it happens

Trigger: Calling PrintServer.Refresh when one or more property queries to the spooler (GetDataFromServer) return a failure HRESULT.

Common situations: Remote server offline or renamed; access denied; spooler stopped; network failure between client and print server.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/db1a7b7d20e039f5. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintServer.cpp:1131

PrintServer::
Refresh(
    void
    )
{
    VerifyAccess();

    try
    {
        for(int numOfProperties = 0;
        numOfProperties < refreshPropertiesFilter->Length;
        numOfProperties++)
        {
            GetDataFromServer(refreshPropertiesFilter[numOfProperties], true);
        }
    }
    catch (InternalPrintSystemException^ internalException)
    {
        throw CreatePrintServerException(internalException->HResult, "PrintSystemException.PrintServer.Refresh");
    }
}

/*++

Routine Name:

    InternalDispose

Routine Description:

    Internal Dispose method.

Arguments:

    None

Return Value:

View on GitHub (pinned to 81131a70a4)