dotnet/wpf · error · PrintServerException

PrintSystemException.PrintServer.Generic

Error message

PrintSystemException.PrintServer.Generic

What it means

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.

Solutions

  1. Verify the server name/UNC path passed to PrintServer is correct and reachable
  2. Check that the Print Spooler service runs on the target machine
  3. Run under an account with rights to the print server
  4. Use the exception HResult to identify the specific Win32 error

Example fix

// before
var server = new PrintServer("\\\" + unknownHost);
// after
var server = new PrintServer(); // local server, avoids name-resolution failures
// or validate first: queue names via net view / GetPrintQueues with try-catch
Defensive patterns

Strategy: try-catch

Validate before calling

if (!Uri.CheckHostName(serverName)) throw new ArgumentException("Invalid server name");
using (var p = Process.GetProcessesByName("spoolsv", serverName))
    if (p.Length == 0) throw new InvalidOperationException("Spooler not running on " + serverName);

Type guard

static bool ServerReachable(string name) =>
    string.IsNullOrEmpty(name) || Dns.GetHostEntry(name) != null;

Try / catch

try { /* PrintServer ops */ }
catch (PrintSystemException ex)
{
    Log.Error($"PrintServer op failed 0x{ex.HResult:X}");
    if (ex.HResult == unchecked((int)0x80070005)) throw new UnauthorizedAccessException("Access denied to print server", ex);
    throw;
}

Prevention

When it happens

Trigger: 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.

Common situations: Print server name unresolvable or wrong; insufficient rights on remote server; spooler service down; network unreachable for remote queues.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/PrintServer.cpp:442

        if (serverThunkHandler)
        {
            this->IsInternallyInitialized = true;

            this->Name = path ? path : PrinterThunkHandler::GetLocalMachineName();

            refreshPropertiesFilter = PrintServer::GetAllPropertiesFilter(propertiesFilter);

            if (!isDelayInitialized)
            {
                GetUnInitializedData(refreshPropertiesFilter);
            }
        }
    }
    catch (InternalPrintSystemException^ internalException)
    {
        disposeServerHandle = true;

        throw CreatePrintServerException(internalException->HResult, "PrintSystemException.PrintServer.Generic");
    }
    __finally
    {
        if (disposeServerHandle &&
            serverThunkHandler)
        {
            delete serverThunkHandler;
            serverThunkHandler = nullptr;
        }
    }
}

/*++

Routine Name:

    InitializeInternalCollections

View on GitHub (pinned to 81131a70a4)