dotnet/wpf · error · PrintServerException
PrintSystemException.PrintServer.SetDefaultPrinter
Error message
PrintSystemException.PrintServer.SetDefaultPrinter
What it means
Thrown when setting LocalPrintServer.DefaultPrintQueue fails. The property setter calls ThunkSetDefaultPrinter with the full queue name; a Win32 failure (queue not found, access denied) is wrapped as this PrintSystemException.
Solutions
- Confirm the queue exists and is connectable before assigning it (server.GetPrintQueues().Contains / FullName lookup).
- For remote queues, connect to the queue first (ConnectToPrintQueue) before making it default.
- Run in the target user's session; changing a default printer affects the current user's profile only.
- Check the inner HResult (e.g. ERROR_FILE_NOT_FOUND, ERROR_ACCESS_DENIED) for the root cause.
Example fix
// before server.DefaultPrintQueue = someRemoteQueue; // may throw if not connected // after server.ConnectToPrintQueue(someRemoteQueue.FullName); server.DefaultPrintQueue = someRemoteQueue;
Defensive patterns
Strategy: validation
Validate before calling
var exists = server.GetPrintQueues().Any(q => q.FullName == newDefault.FullName);
if (!exists) throw new InvalidOperationException($"Cannot set default: {newDefault.FullName} not found"); Type guard
static bool CanSetDefault(LocalPrintServer server, PrintQueue q) =>
server.GetPrintQueues().Any(x => x.FullName == q.FullName) && !q.IsOffline; Try / catch
try { server.DefaultPrintQueue = newDefault; }
catch (PrintSystemException ex)
{
logger.LogError(ex.InnerException, "Setting default printer {Name} failed", newDefault.FullName);
} Prevention
- Connect to remote queues before making them default
- Only change defaults in the target user's interactive session
- Re-check queue existence right before assignment
When it happens
Trigger: Assigning LocalPrintServer.DefaultPrintQueue = someQueue where the queue name cannot be resolved by the spooler (queue deleted, remote queue not connected, or the process lacks permission to change the user's default printer).
Common situations: Setting a default from a queue obtained on a different server/session; service or elevated process changing HKCU printer settings for another user; queue removed by group policy between enumeration and assignment.
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.PrintQueue.Pause
- PrintSystemException.PrintQueue.Purge
- PrintSystemException.PrintServer.Commit
- PrintSystemException.PrintServer.GetDefaultPrinter
- PrintSystemException.PrintSystemJobInfo.Generic
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/52556cd260254b53.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Printing/CPP/src/LocalPrintServer.cpp:1023
{
for(int propertyIndex = 0;
propertyIndex < properties->Length;
propertyIndex++)
{
PrintProperty^ attributeValue = attributeValue = PropertiesCollection->GetProperty(properties[propertyIndex]);
//
// hase something table driven
//
if (attributeValue->Name->Equals("DefaultPrintQueue"))
{
try
{
PrintWin32Thunk::PrinterThunkHandler::ThunkSetDefaultPrinter(GetFullPrintQueueName((PrintQueue^)attributeValue->Value));
}
catch (InternalPrintSystemException^ internalException)
{
throw CreatePrintServerException(internalException->HResult, "PrintSystemException.PrintServer.SetDefaultPrinter");
}
}
}
}
}
/*++
Routine Name:
Commit
Routine Description:
Commits the dirty attributes to server.
Arguments:View on GitHub (pinned to 81131a70a4)