{"record":{"id":"89104cbeeb74d02e","repo":"dotnet/wpf","slug":"printsystemexception-printqueue-populate","errorCode":null,"errorMessage":"PrintSystemException.PrintQueue.Populate","messagePattern":"PrintSystemException\\.PrintQueue\\.Populate","errorType":"exception","errorClass":"PrintQueueException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintQueue.cpp","lineNumber":589,"sourceCode":"        // Call the thunking code to populate the required properties of the\n        // PrintQueue Object\n        //\n        dataThunkObject = gcnew GetDataThunkObject(this->GetType());\n        dataThunkObject->PopulatePrintSystemObject(printerThunkHandler,\n                                                   this,\n                                                   propertiesAsStrings);\n        //\n        // When an object consumer asks for a refresh on the object,\n        // I only refresh the properties that he already asked for and\n        // those are maintained in the following array\n        //\n        refreshPropertiesFilter = propertiesAsStrings;\n    }\n    catch (InternalPrintSystemException^ internalException)\n    {\n        disposePrinterThunkHandler = true;\n\n        throw CreatePrintQueueException(internalException->HResult, \"PrintSystemException.PrintQueue.Populate\");\n    }\n    __finally\n    {\n        if (disposePrinterThunkHandler &&\n            printerThunkHandler)\n        {\n            delete printerThunkHandler;\n            printerThunkHandler = nullptr;\n        }\n\n        if (dataThunkObject)\n        {\n            delete dataThunkObject;\n            dataThunkObject = nullptr;\n        }\n\n        if (printerDefaults)\n        {","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintQueue.cpp#L571-L607","documentation":"Thrown from PrintQueue::Populate when refreshing the queue's property collections fails: the internal printer thunk call that reads spooler properties throws InternalPrintSystemException, and the code converts it to CreatePrintQueueException with key PrintSystemException.PrintQueue.Populate before disposing the thunk handler. The queue's properties could not be fetched from the spooler.","triggerScenarios":"Calling Refresh() or accessing lazily-populated PrintQueue properties (e.g. GetPrintCapabilities, QueueStatus, HostingPrintServer) when the printer handle is stale/invalid, the printer was deleted, or the spooler denies the property query.","commonSituations":"Long-lived PrintQueue objects used after the printer was removed/reinstalled; accessing properties of a queue on an offline print server; partial-trust apps denied property access; spooler restarted between object creation and Refresh.","solutions":["Recreate the PrintQueue object instead of Refreshing a long-lived one whose printer may have changed","Catch PrintSystemException around Refresh/property access and fall back to cached values or re-enumerate","Check printer existence and spooler health when Populate fails repeatedly","Ensure required PropertiesFilter names are valid; an invalid filter can cause the property query to fail"],"exampleFix":"// before\nqueue.Refresh();\nvar status = queue.QueueStatus;\n// after\ntry { queue.Refresh(); var status = queue.QueueStatus; }\ncatch (PrintSystemException) { queue = server.GetPrintQueue(queue.Name); /* rebuild */ }","handlingStrategy":"fallback","validationCode":"if (queue == null) return;\ntry { _ = queue.QueueStatus; } // probe\ncatch (PrintSystemException) { queue = server.GetPrintQueue(queue.Name); }","typeGuard":"static bool QueueIsValid(PrintQueue q) { try { _ = q.QueueStatus; return true; } catch (PrintSystemException) { return false; } }","tryCatchPattern":"try { queue.Refresh(); }\ncatch (PrintSystemException) { cached = Snapshot(queue); /* fall back to cached values */ }","preventionTips":["Prefer short-lived PrintQueue objects over long-cached ones","Wrap Refresh/property access in fallback-to-cache logic","Rebuild the queue object whenever Populate fails","Keep the PropertiesFilter to valid property names only"],"tags":["wpf","printing","printqueue","refresh"],"backgroundTag":"print-queue-open-failed","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"}