{"record":{"id":"c47af486dd78861e","repo":"dotnet/wpf","slug":"printsystemexception-printqueue-refresh","errorCode":null,"errorMessage":"PrintSystemException.PrintQueue.Refresh","messagePattern":"PrintSystemException\\.PrintQueue\\.Refresh","errorType":"exception","errorClass":"PrintQueueException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintQueue.cpp","lineNumber":3344,"sourceCode":"        if (isBrowsable)\n        {\n            ActivateBrowsableQueue();\n            isBrowsable = false;\n        }\n\n        dataThunkObject = gcnew GetDataThunkObject(this->GetType());\n\n        dataThunkObject->PopulatePrintSystemObject(printerThunkHandler,\n                                                    this,\n                                                    refreshPropertiesFilter);\n        //\n        // Making sure that the Full Name reflects the current name\n        //\n        fullQueueName = PrepareNameForDownLevelConnectivity(hostingPrintServer->Name,Name);\n    }\n    catch (InternalPrintSystemException^ internalException)\n    {\n        throw CreatePrintQueueException(internalException->HResult, \"PrintSystemException.PrintQueue.Refresh\");\n    }\n    __finally\n    {\n        delete dataThunkObject;\n    }\n}\n\n/*++\n    Function Name:\n        GetAllPropertiesFilter\n\n    Description:\n        The method populates a String Array of all\n        possible properties of the PrintQueue object.\n\n    Parameters:\n        None\n","sourceCodeStart":3326,"sourceCodeEnd":3362,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintQueue.cpp#L3326-L3362","documentation":"PrintQueue.Refresh wraps a failure while re-reading queue data (including PrepareNameForDownLevelConnectivity for downlevel servers) into a PrintSystemException tagged 'PrintSystemException.PrintQueue.Refresh'. The HResult carries the Win32 error from the underlying spooler call.","triggerScenarios":"Calling queue.Refresh() when the queue handle cannot be opened under its current FullName/HostingPrintServer — e.g. the printer was renamed, deleted, or the downlevel name mapping fails.","commonSituations":"Stale PrintQueue reference after printer rename/removal; connecting to a downlevel Windows print server with an unexpected name; offline network share; spooler restarted with the queue recreated under a new name.","solutions":["Re-resolve the queue via PrintServer.GetPrintQueue(queue.Name) to pick up the current full name, then refresh.","Verify the printer still exists and the server name is correct before refreshing.","Check network connectivity to the print server and that the spooler service is running.","Wrap Refresh in retry/fallback and treat persistent failures as 'queue gone' by re-enumerating queues."],"exampleFix":"// before\nqueue.Refresh();\n// after\ntry { queue.Refresh(); }\ncatch (PrintSystemException)\n{\n    queue = server.GetPrintQueue(queue.Name); // re-resolve renamed/recreated queue\n    queue.Refresh();\n}","handlingStrategy":"try-catch","validationCode":"var current = server.GetPrintQueues().FirstOrDefault(q => q.Name == queue.Name);\nif (current == null) throw new InvalidOperationException($\"Queue '{queue.Name}' no longer exists\");","typeGuard":null,"tryCatchPattern":"try { queue.Refresh(); }\ncatch (PrintSystemException)\n{\n    queue = server.GetPrintQueue(queue.Name); // re-resolve stale/renamed queue\n    queue.Refresh();\n}","preventionTips":["Re-enumerate queues after printer renames or server maintenance instead of refreshing stale objects.","Validate network connectivity to the print server in retry logic.","Use the queue's current FullName from the server, not a cached one.","Watch spooler service health before bulk Refresh() calls."],"tags":["printing","wpf","stale-handle"],"backgroundTag":"resource-not-found","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"}