dotnet/wpf · error · PrintServerException
PrintSystemException.PrintServer.DeleteConnection
Error message
PrintSystemException.PrintServer.DeleteConnection
What it means
Thrown when disconnecting from a network print queue by path fails. ThunkDeletePrinterConnection calls the Win32 DeletePrinterConnection API; any spooler error is wrapped in a PrintSystemException with the DeleteConnection key.
Solutions
- Check the connection exists first via GetPrintQueues / net use before calling DisconnectFromPrintQueue.
- Use the exact same path string used when the connection was added (same server name form).
- Remember connections are per-user: run in the same user context that created the connection.
- Inspect the inner HResult for the specific Win32 error.
Example fix
// before: blind disconnect
server.DisconnectFromPrintQueue(@"\\printserver\LaserJet");
// after: only disconnect existing connections
if (server.GetPrintQueues().Any(q => q.FullName == @"\\printserver\LaserJet"))
server.DisconnectFromPrintQueue(@"\\printserver\LaserJet"); Defensive patterns
Strategy: validation
Validate before calling
bool isConnected = server.GetPrintQueues().Any(q => q.FullName == printQueuePath); if (!isConnected) return; // nothing to disconnect
Type guard
static bool IsConnected(LocalPrintServer server, string path) =>
server.GetPrintQueues().Any(q => q.FullName == path); Try / catch
try { server.DisconnectFromPrintQueue(path); }
catch (PrintSystemException ex)
{
logger.LogWarning("Disconnect failed for {Path}: {HResult}", path, ex.InnerException?.HResult);
} Prevention
- Only disconnect connections you previously created in the same user session
- Use the exact path string used at connect time
- Treat disconnect failures as non-fatal in cleanup code
When it happens
Trigger: Calling LocalPrintServer.DisconnectFromPrintQueue(printQueuePath) for a path that was never connected, is misspelled, or where the connection is held by another process/session the caller cannot modify.
Common situations: Trying to disconnect a queue that doesn't exist in the user's connections; deleting connections per-machine vs per-user confusion (connections are per-user); path casing/server alias mismatches (FQDN vs NetBIOS name).
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- PrintSystemException.PrintServer.AddConnection
- ArgumentException.NonNegativeValue (Parameter 'squareScale')
- ArgumentException.PositiveValue (Parameter 'value')
- ArgumentException.PositiveValue (Parameter 'value')
- errMsg (dynamic: message of caught…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d0c3d461a79da171.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/LocalPrintServer.cpp:590
--*/
bool
LocalPrintServer::
DisconnectFromPrintQueue(
String^ printQueuePath
)
{
VerifyAccess();
bool returnValue = false;
try
{
returnValue = PrintWin32Thunk::PrinterThunkHandler::ThunkDeletePrinterConnection(printQueuePath);
}
catch (InternalPrintSystemException^ internalException)
{
throw CreatePrintServerException(internalException->HResult, "PrintSystemException.PrintServer.DeleteConnection");
}
return returnValue;
}
/*++
Routine Name:
DisconnectFromPrintQueue
Routine Description:
Deletes a printer connection to a given printer.
Arguments:
printerPath - \\server\share or \\server\printerNameView on GitHub (pinned to 81131a70a4)