{"record":{"id":"1dd1d5d04949c904","repo":"dotnet/wpf","slug":"printsystemexception-printserver-commit-1dd1d5","errorCode":null,"errorMessage":"PrintSystemException.PrintServer.Commit","messagePattern":"PrintSystemException\\.PrintServer\\.Commit","errorType":"exception","errorClass":"PrintServerException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintServer.cpp","lineNumber":1089,"sourceCode":"\n    void\n\n--*/\nvoid\nPrintServer::\nCommit(\n    void\n    )\n{\n    VerifyAccess();\n\n    try\n    {\n        ComitDirtyData(GetAlteredPropertiesFilter());\n    }\n    catch (InternalPrintSystemException^ internalException)\n    {\n        throw CreatePrintServerException(internalException->HResult, \"PrintSystemException.PrintServer.Commit\");\n    }\n}\n\n/*++\n\nRoutine Name:\n\n    Refresh\n\nRoutine Description:\n\n    Refreshes the object attributes.\n\nArguments:\n\n    None\n\nReturn Value:","sourceCodeStart":1071,"sourceCodeEnd":1107,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintServer.cpp#L1071-L1107","documentation":"PrintServer.Commit persists altered properties to the spooler. If the native ComitDirtyData call fails with an InternalPrintSystemException, the HRESULT is re-thrown as PrintSystemException keyed 'PrintSystemException.PrintServer.Commit'. It means committing the server's dirty (changed) settings to the print server failed.","triggerScenarios":"Calling PrintServer.Commit after mutating properties (e.g. via InstallPrintQueue or property setters) when the spooler rejects the change.","commonSituations":"Read-only property changed; insufficient admin rights to change server settings; remote server refuses configuration changes; spooler error writing configuration.","solutions":["Ensure the process runs elevated / with print-server admin rights","Only set properties that are writable (check IsInternallyInitialized / altered filter)","Check HResult for the specific Win32 failure","Call Refresh before re-committing to resync with the server"],"exampleFix":"// before\nserver.BeepEnabled = true;\nserver.Commit();\n// after\nif (WindowsIdentity.GetCurrent().Owner.IsWellKnown(WellKnownSidType.BuiltinAdministratorsSid))\n{\n    server.BeepEnabled = true;\n    server.Commit();\n}","handlingStrategy":"try-catch","validationCode":"var admin = new WindowsPrincipal(WindowsIdentity.GetCurrent());\nif (!admin.IsInRole(WindowsBuiltInRole.Administrator))\n    throw new UnauthorizedAccessException(\"Commit requires admin rights\");","typeGuard":"static bool CanCommit(PrintServer s) =>\n    s != null && new WindowsPrincipal(WindowsIdentity.GetCurrent())\n        .IsInRole(WindowsBuiltInRole.Administrator);","tryCatchPattern":"try { server.Commit(); }\ncatch (PrintSystemException ex)\n{ Log.Error($\"Commit failed 0x{ex.HResult:X}\"); server.Refresh(); throw; }","preventionTips":["Only change writable properties","Run elevated when changing server settings","Call Refresh before re-committing after a failure","Batch property changes into a single Commit"],"tags":["printing","print-server","commit","permissions"],"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-21T21:30:21.729Z"}