{"record":{"id":"85afcedf923e804b","repo":"dotnet/wpf","slug":"printsystemexception-printserver-refresh","errorCode":null,"errorMessage":"PrintSystemException.PrintServer.Refresh","messagePattern":"PrintSystemException\\.PrintServer\\.Refresh","errorType":"exception","errorClass":"PrintServerException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/LocalPrintServer.cpp","lineNumber":1103,"sourceCode":"    void\n\n--*/\nvoid\nLocalPrintServer::\nRefresh(\n    void\n    )\n{\n    VerifyAccess();\n\n    try\n    {\n        GetDataFromServer(\"DefaultPrintQueue\", true);\n        PrintServer::Refresh();\n    }\n    catch (InternalPrintSystemException^ internalException)\n    {\n        throw CreatePrintServerException(internalException->HResult, \"PrintSystemException.PrintServer.Refresh\");\n}\n\n}\n\n/*++\n\nRoutine Name:\n\n    GetAlteredPropertiesFilter\n\nRoutine Description:\n\n    Creates an array string representing of the dirty properties of a PrintServer object.\n\nArguments:\n\n    propertiesFilter - array of property strings\n","sourceCodeStart":1085,"sourceCodeEnd":1121,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/LocalPrintServer.cpp#L1085-L1121","documentation":"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.","triggerScenarios":"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.","commonSituations":"Print Spooler restarted or crashed between operations; environment with no printers (services, CI agents); driver/provider corruption causing GetPrinter failures.","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."],"exampleFix":"// before\nserver.Refresh(); // may throw on headless/service sessions\n// after\ntry { server.Refresh(); }\ncatch (PrintSystemException ex)\n{\n    // spooler unavailable or no default printer; fall back to re-enumeration\n    server = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);\n}","handlingStrategy":"retry","validationCode":"using var sc = new ServiceController(\"Spooler\");\nsc.Refresh();\nif (sc.Status != ServiceControllerStatus.Running) throw new InvalidOperationException(\"Spooler not running\");","typeGuard":"static bool SpoolerRunning()\n{\n    try { using var sc = new ServiceController(\"Spooler\"); sc.Refresh();\n          return sc.Status == ServiceControllerStatus.Running; }\n    catch { return false; }\n}","tryCatchPattern":"for (int attempt = 0; attempt < 3; attempt++)\n{\n    try { server.Refresh(); break; }\n    catch (PrintSystemException) when (attempt < 2) { Thread.Sleep(500); }\n}","preventionTips":["Check Spooler service status before refresh","Retry transient failures with backoff (spooler restarts)","Re-create the LocalPrintServer instance if refresh keeps failing"],"tags":["printing","spooler","refresh","wpf"],"backgroundTag":"api-error-response","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}