{"record":{"id":"fc173b220cf8741d","repo":"dotnet/wpf","slug":"printsystemexception-printserver-generic","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/LocalPrintServer.cpp","lineNumber":102,"sourceCode":"LocalPrintServer::\nLocalPrintServer(\n    void\n    ):\nPrintServer(),\ndefaultPrintQueue(nullptr),\naccessVerifier(nullptr)\n{\n    try\n    {\n        Initialize();\n\n        this->IsInternallyInitialized = true;\n\n        refreshPropertiesFilter = LocalPrintServer::GetAllPropertiesFilter();\n    }\n    catch (InternalPrintSystemException^ internalException)\n    {\n        throw CreatePrintServerException(internalException->HResult, \"PrintSystemException.PrintServer.Generic\");\n    }\n}\n\n/*++\n\nRoutine Name:\n\n    LocalPrintServer\n\nRoutine Description:\n\n    Constructor\n\nArguments:\n\n    type    - print server type.\n\nReturn Value:","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/LocalPrintServer.cpp#L84-L120","documentation":"The parameterless LocalPrintServer constructor initializes the object against the local print spooler and requests all server properties. If the underlying spooler call fails (wrapped as InternalPrintSystemException), it is translated via CreatePrintServerException with the message key 'PrintSystemException.PrintServer.Generic', producing a PrintSystemException whose HResult carries the Win32 spooler error (e.g. service stopped, access denied).","triggerScenarios":"Executing new LocalPrintServer() when the Print Spooler (Spooler) service is not running, RPC to the spooler fails, or the caller lacks permission to query server properties — Initialize() throws InternalPrintSystemException caught at LocalPrintServer.cpp:100-103.","commonSituations":"Print Spooler service disabled or crashed on the machine; running in a service/session (e.g. IIS, non-interactive Windows service) without spooler access; missing printer drivers/spooler corruption; restricted user accounts or group policy blocking print server enumeration.","solutions":["Start/restart the Print Spooler service: run 'net start spooler' or check services.msc.","Catch PrintSystemException and inspect its HResult/inner Win32 error to identify the spooler failure (0x800706BA RPC unavailable, 0x5 access denied, etc.).","Ensure the process runs as a user with rights to the local print server; use the PrintSystemDesiredAccess overload to request only needed access.","If running in a service or container, enable/print-enable the spooler or run on a machine with a functioning print subsystem.","Repair spooler state: clear %SYSTEMROOT%\\System32\\spool\\PRINTERS queued jobs and restart the service."],"exampleFix":"// before\nvar server = new LocalPrintServer(); // throws if spooler is stopped\n\n// after\ntry\n{\n    var server = new LocalPrintServer();\n}\ncatch (PrintSystemException ex)\n{\n    // check spooler service / permissions using ex.HResult\n}","handlingStrategy":"try-catch","validationCode":"// Verify the spooler service is running before constructing LocalPrintServer\nusing var sc = new System.ServiceProcess.ServiceController(\"Spooler\");\nbool ready = sc.Status == System.ServiceProcess.ServiceControllerStatus.Running;\nif (!ready) throw new InvalidOperationException(\"Print Spooler service is not running\");","typeGuard":"static bool SpoolerAvailable()\n{\n    try\n    {\n        using var sc = new System.ServiceProcess.ServiceController(\"Spooler\");\n        return sc.Status == System.ServiceProcess.ServiceControllerStatus.Running;\n    }\n    catch { return false; }\n}","tryCatchPattern":"try\n{\n    using var server = new LocalPrintServer();\n}\ncatch (PrintSystemException ex)\n{\n    // ex.HResult -> Win32 spooler error (access denied / service unavailable)\n    logger.LogError(ex, \"LocalPrintServer init failed, HResult=0x{HR:X}\", ex.HResult);\n}","preventionTips":["Check the Print Spooler service status before printing features run.","Never assume spooler access in services/CI — probe with ServiceController or a health check.","Catch PrintSystemException at the boundary and degrade gracefully (printing is optional in most apps).","Log the HResult to distinguish access-denied from service-unavailable failures."],"tags":["printing","wpf","spooler","windows","printserver"],"backgroundTag":"print-server-initialization-failed","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"}