{"record":{"id":"760a5278fa0b8ce4","repo":"dotnet/wpf","slug":"printsystemexception-printserver-generic-760a52","errorCode":null,"errorMessage":"PrintSystemException.PrintServer.Generic","messagePattern":"PrintSystemException\\.PrintServer\\.Generic","errorType":"exception","errorClass":"PrintServerException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintServer.cpp","lineNumber":442,"sourceCode":"        if (serverThunkHandler)\n        {\n            this->IsInternallyInitialized = true;\n\n            this->Name = path ? path : PrinterThunkHandler::GetLocalMachineName();\n\n            refreshPropertiesFilter = PrintServer::GetAllPropertiesFilter(propertiesFilter);\n\n            if (!isDelayInitialized)\n            {\n                GetUnInitializedData(refreshPropertiesFilter);\n            }\n        }\n    }\n    catch (InternalPrintSystemException^ internalException)\n    {\n        disposeServerHandle = true;\n\n        throw CreatePrintServerException(internalException->HResult, \"PrintSystemException.PrintServer.Generic\");\n    }\n    __finally\n    {\n        if (disposeServerHandle &&\n            serverThunkHandler)\n        {\n            delete serverThunkHandler;\n            serverThunkHandler = nullptr;\n        }\n    }\n}\n\n/*++\n\nRoutine Name:\n\n    InitializeInternalCollections\n","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintServer.cpp#L424-L460","documentation":"CreatePrintServerException wraps a native spooler HRESULT (from InternalPrintSystemException) into a PrintSystemException with the generic key 'PrintSystemException.PrintServer.Generic'. Thrown from general PrintServer operations in PrintServer.cpp when any native Win32 spooler call fails during property/data retrieval or other server operations.","triggerScenarios":"Any PrintServer operation (construction, property access, enumeration) whose underlying OpenPrinter/spooler call returns a failure HRESULT; the catch-all handler at PrintServer.cpp:442 converts it.","commonSituations":"Print server name unresolvable or wrong; insufficient rights on remote server; spooler service down; network unreachable for remote queues.","solutions":["Verify the server name/UNC path passed to PrintServer is correct and reachable","Check that the Print Spooler service runs on the target machine","Run under an account with rights to the print server","Use the exception HResult to identify the specific Win32 error"],"exampleFix":"// before\nvar server = new PrintServer(\"\\\\\\\" + unknownHost);\n// after\nvar server = new PrintServer(); // local server, avoids name-resolution failures\n// or validate first: queue names via net view / GetPrintQueues with try-catch","handlingStrategy":"try-catch","validationCode":"if (!Uri.CheckHostName(serverName)) throw new ArgumentException(\"Invalid server name\");\nusing (var p = Process.GetProcessesByName(\"spoolsv\", serverName))\n    if (p.Length == 0) throw new InvalidOperationException(\"Spooler not running on \" + serverName);","typeGuard":"static bool ServerReachable(string name) =>\n    string.IsNullOrEmpty(name) || Dns.GetHostEntry(name) != null;","tryCatchPattern":"try { /* PrintServer ops */ }\ncatch (PrintSystemException ex)\n{\n    Log.Error($\"PrintServer op failed 0x{ex.HResult:X}\");\n    if (ex.HResult == unchecked((int)0x80070005)) throw new UnauthorizedAccessException(\"Access denied to print server\", ex);\n    throw;\n}","preventionTips":["Resolve server names before constructing PrintServer","Run under an account with print-server access","Verify spooler service on remote machines","Log HResult codes for diagnosis"],"tags":["printing","print-server","native-interop","win32"],"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-22T01:17:13.364Z"}