dotnet/wpf · error · PrintServerException

PrintSystemException.PrintServer.Commit

Error message

PrintSystemException.PrintServer.Commit

What it means

Thrown by LocalPrintServer.Commit when writing dirty server properties back to the spooler fails. LocalPrintServer first commits its own dirty data (ComitDirtyData) then calls PrintServer::Commit; any InternalPrintSystemException from those Win32 operations is converted to this PrintSystemException.

Solutions

  1. Run with administrator privileges when committing server-level (machine-wide) print settings.
  2. Validate changed property values before Commit (paths exist, enums valid).
  3. Catch the exception and inspect the inner HResult to find which property failed.
  4. Commit only properties you actually changed; avoid wholesale Refresh/Commit cycles on read-only servers.

Example fix

// before
server.DefaultPrintQueue = queue;
server.Commit(); // requires admin for server settings
// after
if (IsElevated())
{
    server.DefaultPrintQueue = queue;
    server.Commit();
}
Defensive patterns

Strategy: try-catch

Validate before calling

static bool IsElevated()
{
    using var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
    var principal = new System.Security.Principal.WindowsPrincipal(identity);
    return principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
}

Type guard

static bool CanCommitServerSettings() => IsElevated();

Try / catch

try { server.Commit(); }
catch (PrintSystemException ex)
{
    throw new UnauthorizedAccessException(
        "Committing print server settings requires administrator privileges", ex);
}

Prevention

When it happens

Trigger: Calling LocalPrintServer.Commit() after changing properties (e.g. DefaultPrintQueue, scheduler priority, spool folder) when the Win32 SetPrinter/registry writes fail due to lack of administrator rights or an invalid value.

Common situations: Non-admin processes trying to change machine-wide print server settings; UAC elevation missing; invalid configuration values (e.g. bad spool folder path) written to the print server registry keys.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/7f6452745af718c8. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/LocalPrintServer.cpp:1065

    void

--*/
void
LocalPrintServer::
Commit(
    void
    )
{
    VerifyAccess();

    try
    {
        ComitDirtyData(GetAlteredPropertiesFilter());
        PrintServer::Commit();
    }
    catch (InternalPrintSystemException^ internalException)
    {
        throw CreatePrintServerException(internalException->HResult, "PrintSystemException.PrintServer.Commit");
    }
}

/*++

Routine Name:

    Refresh

Routine Description:

    Refreshes the object attributes.

Arguments:

    None

Return Value:

View on GitHub (pinned to 81131a70a4)