{"record":{"id":"db1a7b7d20e039f5","repo":"dotnet/wpf","slug":"printsystemexception-printserver-refresh-db1a7b","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/PrintServer.cpp","lineNumber":1131,"sourceCode":"PrintServer::\nRefresh(\n    void\n    )\n{\n    VerifyAccess();\n\n    try\n    {\n        for(int numOfProperties = 0;\n        numOfProperties < refreshPropertiesFilter->Length;\n        numOfProperties++)\n        {\n            GetDataFromServer(refreshPropertiesFilter[numOfProperties], true);\n        }\n    }\n    catch (InternalPrintSystemException^ internalException)\n    {\n        throw CreatePrintServerException(internalException->HResult, \"PrintSystemException.PrintServer.Refresh\");\n    }\n}\n\n/*++\n\nRoutine Name:\n\n    InternalDispose\n\nRoutine Description:\n\n    Internal Dispose method.\n\nArguments:\n\n    None\n\nReturn Value:","sourceCodeStart":1113,"sourceCodeEnd":1149,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintServer.cpp#L1113-L1149","documentation":"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.","triggerScenarios":"Calling PrintServer.Refresh when one or more property queries to the spooler (GetDataFromServer) return a failure HRESULT.","commonSituations":"Remote server offline or renamed; access denied; spooler stopped; network failure between client and print server.","solutions":["Verify connectivity to the print server and that its spooler service is running","Check HResult for access-denied (5) vs RPC unavailable errors","Re-create the PrintServer object with a valid name and retry Refresh","Run under credentials with read access to the server"],"exampleFix":"// before\nserver.Refresh(); // throws if server unreachable\n// after\ntry { server.Refresh(); }\ncatch (PrintSystemException ex)\n{\n    Console.WriteLine($\"Refresh failed 0x{ex.HResult:X}; using cached values\");\n}","handlingStrategy":"try-catch","validationCode":"try { Dns.GetHostEntry(serverHost); }\ncatch (SocketException) { throw new InvalidOperationException(\"Print server unreachable: \" + serverHost); }","typeGuard":"static bool CanRefresh(PrintServer s) =>\n    s != null && ServiceController\n        .GetServices(s.Name == \"\" ? \".\" : s.Name)\n        .Any(x => x.ServiceName == \"Spooler\" && x.Status == ServiceControllerStatus.Running);","tryCatchPattern":"try { server.Refresh(); }\ncatch (PrintSystemException ex)\n{ Log.Warn($\"Refresh failed 0x{ex.HResult:X}; using cached data\"); }","preventionTips":["Confirm network/server availability before Refresh","Keep cached property values as fallback","Catch and treat refresh failure as degradation, not fatal","Check spooler health on the remote host"],"tags":["printing","print-server","refresh","network"],"backgroundTag":"http-error-response","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}