{"record":{"id":"9a8ec3415540f42c","repo":"dotnet/wpf","slug":"printsystemexception-printqueue-generic","errorCode":null,"errorMessage":"PrintSystemException.PrintQueue.Generic","messagePattern":"PrintSystemException\\.PrintQueue\\.Generic","errorType":"exception","errorClass":"PrintQueueException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintQueue.cpp","lineNumber":475,"sourceCode":"printTicketManager(nullptr),\nisBrowsable(true),\nrefreshPropertiesFilter(nullptr),\nhostingPrintServer(nullptr),\nfullQueueName(nullptr),\nclientPrintSchemaVersion(1),\nprintingIsCancelled(false),\naccessVerifier(nullptr),\n_lockObject(gcnew Object())\n{\n    try\n    {\n        InPartialTrust = false;\n        InitializeInternalCollections();\n        refreshPropertiesFilter = propertiesFilter;\n    }\n    catch (InternalPrintSystemException^ internalException)\n    {\n        throw CreatePrintQueueException(internalException->HResult, \"PrintSystemException.PrintQueue.Generic\");\n    }\n}\n\n\n\n/*++\n    Function Name:\n        PrintQueue\n\n    Description:\n        Constructor of class instance for a browsable PritnQueue\n        used during enumerations\n\n    Parameters:\n        PrintServer:                The Print Server hosting the print queue\n\n        PrintQueueIndexedProperty[]:       Enums of properties that the queue would be\n                                           initialized with. If someone is interested in a","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintQueue.cpp#L457-L493","documentation":"A generic PrintQueue initialization failure: when the C++/CLI PrintQueue constructor's Initialize completes but the internal catch converts any InternalPrintSystemException into CreatePrintQueueException with key PrintSystemException.PrintQueue.Generic. Any error opening or validating the printer on the spooler during queue construction surfaces here with the original HRESULT preserved.","triggerScenarios":"Constructing a PrintQueue (e.g. new PrintQueue(printServer, queueName) or via LocalPrintServer.GetPrintQueue) when the printer name is invalid, the printer was removed, access is denied, or the spooler call inside Initialize fails.","commonSituations":"Stale or misspelled printer names cached in application settings; printer deleted or renamed between enumeration and use; insufficient permissions to open the printer handle; Print Spooler service stopped.","solutions":["Verify the printer name exists via LocalPrintServer.GetPrintQueues() before constructing the PrintQueue","Read the HResult on the PrintSystemException to identify the underlying Win32 error (0x700 for not-found, 0x5 for access denied)","Confirm the Print Spooler service is running and the printer is online","Run with sufficient privileges or connect as a user with print access to the target queue"],"exampleFix":"// before\nvar queue = new PrintQueue(server, settings.PrinterName);\n// after\nvar name = settings.PrinterName;\nif (server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections })\n        .All(q => q.FullName != name)) throw new InvalidOperationException($\"Printer '{name}' not found\");\nvar queue = new PrintQueue(server, name);","handlingStrategy":"validation","validationCode":"var server = new LocalPrintServer();\nbool exists = server.GetPrintQueues().Any(q => q.FullName == printerName);\nif (!exists) throw new ArgumentException($\"Printer '{printerName}' does not exist\");","typeGuard":"static PrintQueue TryGetQueue(PrintServer s, string name) => s.GetPrintQueues().FirstOrDefault(q => q.FullName == name);","tryCatchPattern":"try { var q = new PrintQueue(server, name); }\ncatch (PrintSystemException ex) { throw new InvalidOperationException($\"Cannot open queue '{name}': 0x{ex.HResult:X}\", ex); }","preventionTips":["Resolve queue names from GetPrintQueues() instead of hard-coding strings","Re-enumerate queues after driver/printer changes","Check spooler service status before constructing queues","Surface the preserved HResult in your own error messages"],"tags":["wpf","printing","printqueue"],"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"}