DefaultPageSettings.PaperSize can terminate the process with 0xc0000005 for an offline printer queue
Disclosure: This issue report was prepared by OpenAI Codex, an AI coding agent, from diagnostic information and test results supplied by the application developer. The report should be reviewed by a human before submission. Customer-identifying information has intentionally been omitted.
.NET version
- Target framework:
net10.0-windows - Process architecture: x64
- .NET runtime:
10.0.12 - CoreCLR:
10.0.1226.42308 - Application type: WPF application using
System.Drawing.Printing.PrinterSettings
Description
Reading PrinterSettings.DefaultPageSettings.PaperSize for one or more offline printer queues can terminate the entire process with native exception code 0xc0000005.
The failure cannot be caught by normal managed try/catch; the process terminates before error logging in the catch block can run.
The problem reproduces on a customer Windows system but not on the developer workstation or server. The application starts normally when printer detail reads are disabled. Isolating the queried properties showed:
- Printer enumeration succeeds.
- Reading
PrintQueue.IsOfflinesucceeds. - Reading
PrinterSettings.PrinterResolutionssucceeds. - Reading
PrinterSettings.DefaultPageSettings.PaperSizecauses the native crash. - Skipping printer detail reads when
PrintQueue.IsOffline == trueprevents the crash. The resulting build has been deployed to the customer and operates successfully.
This may ultimately be caused by a printer driver returning malformed DEVMODE data. Nevertheless, a public managed property getter terminating the process without a catchable managed exception is unexpected.
Minimal code path
using System.Drawing.Printing;
using System.Printing;
using var server = new LocalPrintServer();
var queues = server.GetPrintQueues(
[EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections]);
foreach (var queue in queues)
{
Console.WriteLine($"{queue.FullName}: IsOffline={queue.IsOffline}");
var settings = new PrinterSettings
{
PrinterName = queue.FullName
};
// PrinterResolutions succeeds on the affected system.
var resolutions = settings.PrinterResolutions;
// For an offline queue this can terminate the process with 0xc0000005.
var paperSize = settings.DefaultPageSettings.PaperSize;
Console.WriteLine($"{paperSize.Width} x {paperSize.Height}");
}
The issue currently depends on the affected customer printer/driver configuration; a hardware-independent reproduction has not yet been produced.
Expected behavior
The getter should return the paper size or throw a managed exception describing an invalid/unavailable printer or invalid driver data. It should not terminate the process.
Actual behavior
Windows Application Error / .NET Runtime event:
Application: FiftyWorker.exe
CoreCLR Version: 10.0.1226.42308
.NET Version: 10.0.12
Description: The process was terminated due to an unhandled exception.
Stack:
at Windows.Win32.PInvoke.DocumentProperties(...)
at Windows.Win32.PInvoke.DocumentProperties(...)
at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal(Char*)
at System.Drawing.Printing.PrinterSettings.GetHdevmode()
at System.Drawing.Printing.PageSettings.get_PrinterResolution()
at FiftyWorker.Local.GetPrinterList()
at FiftyWorker.MainWindow..ctor()
at FiftyWorker.Program.Main(System.String[])
A later property-isolation test identified DefaultPageSettings.PaperSize as the crashing read. Both PageSettings.PaperSize and PageSettings.PrinterResolution use the same GetHdevmode() path.
The corresponding Application Error entry was:
Faulting module: coreclr.dll, version 10.0.1226.42308
Exception code: 0xc0000005
Fault offset: 0x00000000003596cf
Workaround
Read PrintQueue.IsOffline before creating/querying PrinterSettings, and skip DefaultPageSettings for offline queues:
if (queue.IsOffline)
{
continue;
}
var settings = new PrinterSettings { PrinterName = queue.FullName };
var paperSize = settings.DefaultPageSettings.PaperSize;
Similar issue search
No issue matching the offline-printer 0xc0000005 failure was found in dotnet/winforms using these searches:
DocumentProperties GetHdevmodeDefaultPageSettings.PaperSize AccessViolationGetHdevmode crashprinter offline access violation
The closest result is #8812, which contains the same PaperSize -> GetHdevmode -> DocumentProperties stack but concerns missing winspool.drv on Windows Nano Server and is not a duplicate of this failure.
Additional information still needed
- Exact Windows edition, version and OS build from the affected system.
- Affected printer queue type: local, shared/network connection, redirected, or other.
- Printer model, driver name, driver provider, driver version/date, INF name and port type. Queue/server/customer names may be anonymized.
- Whether the queue was already offline when the process started.
- Whether the failure remains after restarting the Print Spooler or recreating that exact queue.
- If safely obtainable outside production: a crash dump captured for the original failing build and analyzed with native symbols.
- Result with the latest supported .NET 10 servicing runtime, if newer than
10.0.12is available when the report is submitted. - Whether a minimal standalone x64 console/WPF application reproduces on the affected system.
Safe collection commands for the affected machine
These commands only read system/spooler metadata. They do not query DefaultPageSettings.PaperSize and therefore do not intentionally execute the crashing code path.
Get-ComputerInfo |
Select-Object WindowsProductName, WindowsVersion, OsBuildNumber, OsArchitecture
dotnet --info
dotnet --list-runtimes
Get-CimInstance Win32_Printer |
Select-Object Name, DriverName, PortName, Network, Shared, WorkOffline,
PrinterStatus, DetectedErrorState
Get-CimInstance Win32_PrinterDriver |
Select-Object Name, Version, InfName, DriverPath, SupportedPlatform
Review and anonymize printer names, server names, port names, user names and local paths before posting the output publicly.
@LeafShi1 this looks fairly straight forward, but might be hard to test? Is your team able to have a look?
@hyigit-adelcon Thanks for the detailed information.
I tested the provided minimal repro locally with a print queue where PrintQueue.IsOffline is true. PrinterResolutions and DefaultPageSettings.PaperSize both complete successfully, and I haven't been able to reproduce the 0xc0000005 crash.
This suggests that the offline state alone isn't sufficient to reproduce the issue, and there may be an additional environment-specific condition involved.
Since the reported crash occurs in the shared GetHdevmode() / DocumentProperties() path, would it be possible to provide a crash dump from an affected machine? That would help us inspect the native crash context and determine where the access violation originates.
Leider kann ich keine weiteren Rückmeldungen oder Crash-Dump-Daten zur Verfügung stellen, da das Problem in der PROD-Umgebung des Kunden aufgetreten ist und die betroffenen Drucker nach der Analyse aus dem System entfernt wurden.
Ich glaube nicht, dass ich das Problem unter denselben Bedingungen noch einmal reproduzieren kann.
Falls eine weitere technische Untersuchung unter diesen Umständen nicht möglich ist, könnt ihr das Ticket schließen.
Mein Vorschlag ist - lasst uns das Ticket schliessen.
Sollte das Problem an anderer Stelle nochmal mit anderen Druckertypen/treibern auftauchen, dass koennen wir dieses Issue jederzeit wieder reaktivieren.
Danke fuer Ihre Hilfe hier soweit - beste Gruesse aus Redmond!