dotnet/wpf · error · PrintServerException

PrintSystemException.PrintServer.NameCannotChange

Error message

PrintSystemException.PrintServer.NameCannotChange

What it means

This error is thrown by System.Printing's PrintServer.Name property setter when you attempt to rename a PrintServer object. A print server's name is fixed by the spooler/OS and cannot be changed through this API; when the new name differs from the current one, the setter releases its lock and throws a PrintSystemException carrying HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) with lookup key PrintSystemException.PrintServer.NameCannotChange. It exists to signal an inherently unsupported operation rather than a transient failure.

Solutions

  1. Do not rename the PrintServer; create a new PrintServer with the desired name instead: new PrintServer(@"\\ServerName") and discard the old instance.
  2. If the goal is to target a remote server, pass the server path to the PrintServer constructor rather than mutating Name.
  3. If the assignment is generated by generic property-setting code, special-case the Name property for PrintServer and skip it.
  4. Wrap the Name setter in a try/catch for PrintSystemException only if the rename is best-effort and can be ignored.

Example fix

// before
PrintServer server = new PrintServer();
server.Name = "\\\\OtherServer"; // throws PrintSystemException.PrintServer.NameCannotChange
// after
PrintServer server = new PrintServer("\\\\OtherServer");
Defensive patterns

Strategy: try-catch

Validate before calling

if (server.Name != newName)
    throw new NotSupportedException("PrintServer.Name cannot be changed; construct a new PrintServer instead.");

Type guard

static bool CanRename(PrintServer s, string newName) => s != null && string.Equals(s.Name, newName, StringComparison.Ordinal);

Try / catch

try { server.Name = newName; }
catch (PrintSystemException ex) when (ex.Message.Contains("NameCannotChange")) {
    server = new PrintServer(newName);
}

Prevention

When it happens

Trigger: Assigning a different value to PrintServer.Name (e.g. printServer.Name = "NewServer") — the C++ setter in PrintServer.cpp detects the name change and throws ERROR_NOT_SUPPORTED. Setting Name to the same value does not throw.

Common situations: Scripts or admin tools that generically set properties on print-system objects reused across PrintQueue and PrintServer types; renaming code copied from PrintQueue examples applied to a PrintServer; attempts to redirect to a remote print server by changing Name instead of constructing a new PrintServer.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

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

set(
    String^ name
    )
{
    try
    {
        System::Threading::Monitor::Enter(SyncRoot);

        if (IsInternallyInitialized)
        {
            PropertiesCollection->GetProperty("Name")->IsInternallyInitialized = true;

            PrintSystemObject::Name::set(name);
            PropertiesCollection->GetProperty("Name")->Value = name;
        }
        else
        {
            System::Threading::Monitor::Exit(SyncRoot);
            throw CreatePrintServerException(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED),
                                             "PrintSystemException.PrintServer.NameCannotChange"
                                             );
        }
    }
    __finally
    {
        IsInternallyInitialized = false;
        System::Threading::Monitor::Exit(SyncRoot);
    }
}

/*++

Routine Name:

    CreatePropertiesDelegates

Routine Description:

View on GitHub (pinned to 81131a70a4)